﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing;

using Kitware.VTK;

namespace HAVTKPack
{
    /// <summary>
    /// 抽取网格等值面
    /// </summary>
    public class ContourFilter : GeometryFilter
    {

        #region 构造函数

        public ContourFilter(string id, HydrolicGrid hg)
            : base(id)
        {

            this._hg = hg;

            //初始化一个默认值出来




            this._effectiveSign = new List<int[,]>();

            for (int i = 0; i < this._hg.NLayers - 1; i++)
            {
                int[,] ibound = new int[this._hg.NRows - 1, this._hg.NCols - 1];

                this._effectiveSign.Add(ibound);

            }



            this._contourData = new List<double[,]>();

            for (int i = 0; i < this._hg.NLayers - 1; i++)
            {
                double[,] scalar = new double[this._hg.NRows - 1, this._hg.NCols - 1];

                this._contourData.Add(scalar);

            }


            this._nRows = this._hg.NRows - 1;
            this._nCols = this._hg.NCols - 1;
            this._nLayers = this._hg.NLayers - 1;


            this._contourSetup = new ContourSetup();






        }

        public ContourFilter(string id, HydrolicGrid hg, List<int[,]> effectiveSign)
            : base(id)
        {

            this._hg = hg;

            if (effectiveSign == null)
            {
                this._effectiveSign = new List<int[,]>();

                for (int i = 0; i < this._hg.NLayers - 1; i++)
                {
                    int[,] ibound = new int[this._hg.NRows - 1, this._hg.NCols - 1];

                    this._effectiveSign.Add(ibound);

                }

            }
            else
            {
                this._effectiveSign = effectiveSign;
            }
           



            this._contourData = new List<double[,]>();

            for (int i = 0; i < this._hg.NLayers - 1; i++)
            {
                double[,] scalar = new double[this._hg.NRows - 1, this._hg.NCols - 1];

                this._contourData.Add(scalar);

            }



            this._nRows = this._hg.NRows - 1;
            this._nCols = this._hg.NCols - 1;
            this._nLayers = this._hg.NLayers - 1;


            this._contourSetup = new ContourSetup();

        }
        public ContourFilter(string id, HydrolicGrid hg, List<int[,]> effectiveSign,ContourSetup contourSetup)
            : base(id)
        {

            this._hg = hg;

            if (effectiveSign == null)
            {
                this._effectiveSign = new List<int[,]>();

                for (int i = 0; i < this._hg.NLayers - 1; i++)
                {
                    int[,] ibound = new int[this._hg.NRows - 1, this._hg.NCols - 1];

                    this._effectiveSign.Add(ibound);

                }

            }
            else
            {
                this._effectiveSign = effectiveSign;
            }


            this._contourData = new List<double[,]>();

            //for (int i = 0; i < this._hg.NLayers - 1; i++)
            //{
            //    double[,] scalar = new double[this._hg.NRows - 1, this._hg.NCols - 1];

            //    this._contourData.Add(scalar);

            //}



            this._nRows = this._hg.NRows - 1;
            this._nCols = this._hg.NCols - 1;
            this._nLayers = this._hg.NLayers - 1;


            if (contourSetup != null)
            {
                this._contourSetup = contourSetup;
            }
            else
            {
                this._contourSetup = new ContourSetup();            
            }

        }







        #endregion


        #region 字段属性



        #region

        int _nRows;

        public int NRows
        {
            get { return _nRows; }
            set { _nRows = value; }
        }
        int _nCols;

        public int NCols
        {
            get { return _nCols; }
            set { _nCols = value; }
        }
        int _nLayers;

        public int NLayers
        {
            get { return _nLayers; }
            set { _nLayers = value; }
        }





        List<int[,]> _effectiveSign;

        public List<int[,]> EffectiveSign1
        {
            get { return _effectiveSign; }
            set
            {


                _effectiveSign = value;


                this.OnSetIbound();


            }
        }




        //int[,] _effectiveSign;

        //public int[,] EffectiveSign
        //{
        //    get { return _effectiveSign; }
        //    set
        //    {

        //        _effectiveSign = value;


        //    }
        //}



        HydrolicGrid _hg;
        /// <summary>
        /// 不规则网格数据源
        /// </summary>
        public HydrolicGrid Hg
        {
            get { return _hg; }
            set
            {

                _hg = value;

                this.OnSetHydrolicGrid();

            }
        }

        #endregion


        #region


        List<double[,]> _contourData;

        public List<double[,]> ContourData
        {
            get { return _contourData; }
            set
            {

                _contourData = value;

                this.OnSetContourData();


            }
        }



        ContourSetup _contourSetup;

        public ContourSetup ContourSetup
        {
            get { return _contourSetup; }
            set
            {

                _contourSetup = value;


                //该Set属性访问器，只会而且只应该在新建立或者整体所有显示配置都需要更新的时候调用
                //这里做的不好了，现在是当主程序切换cellcenterdataset3d的时候，可能导致显示选项部分数据变化（等值线，小数点）
                //而此时更新所有的配置信息 显然不合适
                this.OnSetContourSetup();

            }
        }



        //CONTOURMODE _contourMode = CONTOURMODE.LayerContours;

        //public CONTOURMODE ContourMode
        //{
        //    get { return _contourMode; }
        //    set { _contourMode = value; }
        //}





        #endregion


        Vector scaleVector = new Vector(1, 1, 1);

        public Vector ScaleVector
        {
            get { return scaleVector; }
            set { 
                
                scaleVector = value;

                this.OnSetTransformVector();

            }
        }


        #endregion



        #region   VTK流水线所需对象


        //layers部分



        List<vtkTransform> _transform;
        /// <summary>
        /// 外围要访问的  例如：改变Z轴的缩放
        /// </summary>
        public List<vtkTransform> Transform
        {
            get { return _transform; }
            set { _transform = value; }
        }


        List<vtkTransformFilter> _transformFilter;
 


        [NonSerialized]
        List<vtkUnstructuredGrid> _gridLayers;

        [NonSerialized]
        List<vtkActor> _layerActors;

        [NonSerialized]
        List<vtkDataSetMapper> _layerMappers;

        [NonSerialized]
        //List<vtkColorTransferFunction> _layerLookupTable;
        List<vtkDiscretizableColorTransferFunction> _layerLookupTable;
        //List<vtkLookupTable> _layerLookupTable;




        List<vtkCellDataToPointData> cTop;
        List<vtkContourFilter> contourFilter;
        List<vtkDataSetMapper> _contourLineMapper;
        List<vtkActor> _contourLineActor = new List<vtkActor>();




        [NonSerialized]
        vtkUnstructuredGrid _unGrid;


        [NonSerialized]
        vtkFloatArray scalars;


        vtkFloatArray aArray;
        vtkContourFilter iso;
        vtkPolyDataNormals contourNormals;
        vtkDataSetMapper isoMapper;
        vtkActor isoActor;




        vtkLookupTable lut;
        vtkContourGrid contourGrid;
        vtkScalarBarWidget scalarBarWidget;
        vtkScalarBarActor scalarBarActor;




        //尝试添加标注
        vtkMaskPoints mask;
        vtkSelectVisiblePoints visPts;
        vtkLabeledDataMapper ldm;
        vtkActor2D contourLabels;

        List<vtkMaskPoints> maskList ;
        List<vtkSelectVisiblePoints> visPtsList ;
        List<vtkLabeledDataMapper> ldmList ;
        List<vtkActor2D> contourLabelsList ;


        #endregion



        public override void Render()
        {
            //try
            //{

            //if (this._headScalar == null)
            //{
            //    return;
            //}

            //这里 关键是构造怎样的  PolyData  才能够和 vtkContourFilter 正确交互



            this._unGrid = (vtkUnstructuredGrid)this.ParentNode.Geometry.OutPutData;


            if (_unGrid == null)
            {
                return;
            }






            if (this._contourSetup .ContourMode == CONTOURMODE.LayerContours)
            {
                this.RenderLayerContour();

            }

            else
            {

            }


        }


        public override void StopRender()
        {

            //资源的销毁

            //销毁对应的值


            #region VTK资源的销毁

            for (int i = 0; i < this._contourLineActor.Count; i++)
            {

                if (this._contourLineActor[i] != null)
                {
                    this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().RemoveActor(this._contourLineActor[i]);
                    this._contourLineActor[i].Dispose();
                }
            }
            this._contourLineActor.Clear();

            for (int i = 0; i < this._layerActors .Count ; i++)
            {
                if (this._layerActors [i]!=null )
                {
                    this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().RemoveActor(this._layerActors [i]);
                    this._layerActors [i].Dispose();
                }
            }
            this._layerActors.Clear();

            for (int i = 0; i < this._contourLineMapper .Count ; i++)
            {
                if (this._contourLineMapper [i]!=null )
                {
                    this._contourLineMapper[i].Dispose();
                }
            }
            this._contourLineMapper.Clear();

            for (int i = 0; i < this.contourFilter .Count ; i++)
            {
                if (this.contourFilter [i]!=null )
                {
                    this.contourFilter[i].Dispose();
                }
            }
            this.contourFilter.Clear();

            for (int i = 0; i < this._layerMappers .Count ; i++)
            {
                if (this._layerMappers [i]!=null )
                {
                    this._layerMappers[i].Dispose();
                }
            }
            this._layerMappers.Clear();

            for (int i = 0; i < this._layerLookupTable .Count ; i++)
            {
                if (this._layerLookupTable [i]!=null )
                {
                    this._layerLookupTable[i].Dispose();
                }
            }
            this._layerLookupTable.Clear();

            for (int i = 0; i < this._transformFilter .Count ; i++)
            {
                if (this._transformFilter [i]!=null )
                {
                    this._transformFilter[i].Dispose();
                }
            }
            this._transformFilter.Clear();

            for (int i = 0; i < this._transform .Count ; i++)
            {
                if (this._transform [i]!=null )
                {
                    this._transform[i].Dispose();
                }
            }
            this._transform.Clear();

            //if (this.FilterTransform !=null )
            //{
            //    this.FilterTransform.Dispose();
            //}

            for (int i = 0; i < this.cTop .Count ; i++)
            {
                if (this.cTop [i]!=null )
                {
                    this.cTop[i].Dispose();
                }
            }
            this.cTop.Clear();

            for (int i = 0; i < this._gridLayers .Count ; i++)
            {
                if (this._gridLayers [i]!=null )
                {
                    this._gridLayers[i].Dispose();
                }
            }
            this._gridLayers.Clear();


            #region 标注部分

            //List<vtkMaskPoints> maskList;
            //List<vtkSelectVisiblePoints> visPtsList;
            //List<vtkLabeledDataMapper> ldmList;
            //List<vtkActor2D> contourLabelsList;

            if (contourLabelsList != null)
            {
                for (int i = 0; i < contourLabelsList.Count; i++)
                {
                    if (contourLabelsList[i] != null)
                    {
                        this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().RemoveActor(contourLabelsList[i]);
                        this.contourLabelsList[i].Dispose();
                    }
                }
            }

            if (this.ldmList !=null )
            {
                for (int i = 0; i < ldmList .Count ; i++)
                {

                    if (ldmList [i]!=null )
                    {
                        ldmList[i].Dispose();

                    }
                }
            }
            if (this.visPtsList != null)
            {
                for (int i = 0; i < visPtsList.Count; i++)
                {

                    if (visPtsList[i] != null)
                    {
                        visPtsList[i].Dispose();

                    }
                }
            }
            if (this.maskList != null)
            {
                for (int i = 0; i < maskList.Count; i++)
                {

                    if (maskList[i] != null)
                    {
                        maskList[i].Dispose();

                    }
                }
            }

            //vtkMaskPoints mask;
            //vtkSelectVisiblePoints visPts;
            //vtkLabeledDataMapper ldm;
            //vtkActor2D contourLabels;

            if (this.contourLabels != null)
            {
                this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().RemoveActor(contourLabels);
                this.contourLabels.Dispose();

            }
            if (this.ldm!=null )
            {
                this.ldm.Dispose();
            }
            if (this.visPts != null)
            {
                this.visPts.Dispose();
            }
            if (this.mask != null)
            {
                this.mask.Dispose();
            }



            #endregion



            #region 图例部分


            if (this.scalarBarWidget !=null )
            {
                scalarBarWidget.Dispose();
            }

            if (this.scalarBarActor!=null )
            {

                this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().RemoveActor(scalarBarActor);


                //this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().RemoveActor2D (scalarBarActor);

                this.scalarBarActor.Dispose();

            }


            #endregion



            #region 

            if (this.isoActor != null)
            {
                this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().RemoveActor(isoActor);
                this.isoActor.Dispose();
            }
            if (this.isoMapper != null)
            {
                this.isoMapper.Dispose();
            }

            //if (this.lut !=null )
            //{
            //    this.lut.Dispose();
            //}



            //if (this.ParentNode.Scene.ContourParameter.ContourFilter != null)
            //{
            //    this.ParentNode.Scene.ContourParameter.ContourFilter.Dispose();
            //}


            //if (this.iso != null)
            //{
            //    this.iso.Dispose();
            //}


            if (this.contourNormals != null)
            {
                this.contourNormals.Dispose();
            }



            //if (this.c2p!=null )
            //{
            //    this.c2p.Dispose();
            //}

            if (this.scalars != null)
            {
                this.scalars.Dispose();
            }
            if (this._unGrid != null)
            {
                this._unGrid.Dispose();
            }
            if (this.aArray != null)
            {
                this.aArray.Dispose();
            }


            if (this.ParentNode.Geometry.OutPutData != null)
            {
                this.ParentNode.Geometry.OutPutData.Dispose();
            }

            #endregion



            #endregion



            //throw new NotImplementedException();
        }


      



        #region Render 渲染方法  整个网格  和 逐层Layer


        /// <summary>
        /// 渲染整个网格
        /// </summary>
        protected void RenderAllGridContour()
        {
            //this.RenderGridContour();
        
        }
    

        /// <summary>
        /// 逐层Layer的渲染
        /// </summary>
        protected void RenderLayerContour()
        {


            #region 创建流水线所需要的对象的声明

            //对于流水线的理解还不够深刻，不知道这样理解是否正确：当流水线建立好之后，将其中一环（如vtkColorTransferFunction）的输入数据改变为
            //不再该条流水线中的其他数据集，则该条流水线被破坏。要保证流水线的完整性，需要保持对象不被破坏和接口不转移。
            //故有以下众多流水线对象的声明。


            this._gridLayers = new List<vtkUnstructuredGrid>();

            this.cTop = new List<vtkCellDataToPointData>();



            //this.FilterTransform = vtkTransform.New();

            this._transform = new List<vtkTransform>();

            this._transformFilter = new List<vtkTransformFilter>();

            //this._layerLookupTable = new List<vtkColorTransferFunction>();
            this._layerLookupTable = new List<vtkDiscretizableColorTransferFunction >();
            //this._layerLookupTable = new List<vtkLookupTable>();

            #region 对应于Layer显示的流水线

            this._layerMappers = new List<vtkDataSetMapper>();

            this._layerActors = new List<vtkActor>();

            #endregion


            #region 对应于Layer抽取等值线的流水线


            this.contourFilter = new List<vtkContourFilter>();


            this._contourLineMapper = new List<vtkDataSetMapper>();

            this._contourLineActor = new List<vtkActor>();

            #endregion


            #region 等值线标注

             maskList = new List<vtkMaskPoints>();

             visPtsList = new List<vtkSelectVisiblePoints>();

             ldmList = new List<vtkLabeledDataMapper>();

             contourLabelsList = new List<vtkActor2D>();



            #endregion


            #endregion


            for (int i = 0; i < this._nLayers; i++)
            {

                vtkUnstructuredGrid grid = vtkUnstructuredGrid.New();


                //this.SetLayerPoints(i,grid );
                //this.SetLayerCells(i,grid );
                //this.SetLayerScalarData(i,grid );


                this.BuildGridLayer(i, grid);

                this.SetGridLayerScalar(i, grid);


                this._gridLayers.Add(grid);


                //图例
                vtkMaskPoints maskPoints = vtkMaskPoints.New();
                maskList.Add(maskPoints );

                vtkSelectVisiblePoints selectVisiblePoints = vtkSelectVisiblePoints.New();
                visPtsList.Add(selectVisiblePoints );

                vtkLabeledDataMapper labelDataMapper = vtkLabeledDataMapper.New();
                ldmList.Add(labelDataMapper );


                vtkActor2D actor2d = vtkActor2D.New();
                contourLabelsList.Add(actor2d );


            }


            //foreach (vtkUnstructuredGrid layer in this._gridLayers)
            for (int i = 0; i < this._gridLayers.Count; i++)
            {

                #region  逐层数据着色，抽取等值线并着色，添加标注等操作。

                //vtkUnstructuredGrid layer = this._gridLayers[i];

          

                //double[] sRange = new double[2];
                //if (this.ContourSetup != null)
                //{
                //    sRange[0] = this._contourSetup.ScalarRangeMin;
                //    sRange[1] = this._contourSetup.ScalarRangeMax;
                //}
              
                //首先构筑直接显示模式


                vtkCellDataToPointData cTop;
                //vtkCellDataToPointData cTop = vtkCellDataToPointData.New();
                if (this.cTop.Count >= i + 1)
                {
                    cTop = this.cTop[i];
                }
                else
                {
                    cTop = vtkCellDataToPointData.New();
                    this.cTop.Add(cTop);
                }


                //cTop.SetInput(layer);
                cTop.SetInput(this._gridLayers[i]);
                cTop.PassCellDataOn();
                //cTop.PassCellDataOff();


                vtkTransform transform;
                if (this._transform.Count >= i + 1)
                {
                    transform = this._transform[i];
                }
                else
                {
                    transform = vtkTransform.New();
                    //transform = this.FilterTransform;
                    this._transform.Add(transform );
                }

                transform.Identity();
                transform.Scale(this.scaleVector .X,this.scaleVector .Y,this.scaleVector .Z );




                vtkTransformFilter transformFilter;
                if (this._transformFilter.Count >= i + 1)
                {
                    transformFilter = this._transformFilter[i];
                }
                else
                {
                    transformFilter = vtkTransformFilter.New();
                    this._transformFilter.Add(transformFilter );
                }

                //transformFilter.SetInput(layer); 

                //transformFilter.SetInput(cTop.GetOutput());
                //transformFilter.SetInput(cTop.GetUnstructuredGridOutput());
                transformFilter.SetInput(this.cTop[i].GetUnstructuredGridOutput());
               
                //transformFilter.SetInput(cTop.GetPolyDataOutput ());

                transformFilter.SetTransform(transform);



                //vtkColorTransferFunction lt;
                vtkDiscretizableColorTransferFunction  lt;
                //vtkColorTransferFunction lt = vtkColorTransferFunction.New();
                if (this._layerLookupTable.Count >= i + 1)
                {
                    lt = this._layerLookupTable[i];
                }
                else
                {
                    //lt = vtkColorTransferFunction.New();
                    lt = vtkDiscretizableColorTransferFunction.New();
                    this._layerLookupTable.Add(lt);
                }

                
                //lt.SetRange(sRange[0], sRange[1]);
                lt.SetColorSpaceToRGB();
                lt.SetScaleToLinear();
                lt.DiscretizeOn();
                lt.RemoveAllPoints();

                int numOfValues = 0;

                if (this.ContourSetup == null)
                {
                    this._contourSetup  = new ContourSetup();
                }
                else
                {

                    foreach (var item in this.ContourSetup.DisplayContours)
                    {       
                        //第一个参数为要抽取的等值线值
                        lt.AddRGBPoint(item.Key, item.Value.R / 255.0, item.Value.G / 255.0, item.Value.B / 255.0);
                       
                        numOfValues = numOfValues + 1;
                    
                    }

                }

                lt.SetNumberOfValues(numOfValues);

                lt.Build();//当参数更新后 必须调用build（）更新显示


                #region 网格数据集进行着色显示部分



                //vtkLookupTable lt = new vtkLookupTable();
                //lt.SetNumberOfTableValues(this._contourSetup.NumContours);
                ////lt.SetRange(sRange[0], sRange[1]);
                //lt.SetTableRange(sRange[0], sRange[1]);

                //for (int i = 0; i < this._contourSetup.NumContours; i++)
                //{
                //    lt.SetTableValue(i,this._contourSetup[i].);

                //}

                //foreach (KeyValuePair<double,Color> kv in this._contourSetup.DisplayContours)
                //{
                //    lt.SetTableValue(kv.Key,);

                //}


                vtkDataSetMapper setMapper;
                //vtkDataSetMapper setMapper = vtkDataSetMapper.New();
                if (this._layerMappers.Count >= i + 1)
                {
                    setMapper = this._layerMappers[i];
                }
                else
                {
                    setMapper = vtkDataSetMapper.New();
                    this._layerMappers.Add(setMapper);
                }


                //setMapper.SetInput(layer);
                //setMapper.SetInput(cTop.GetOutput());
                setMapper.SetInput(transformFilter .GetOutput ());


                setMapper.SetLookupTable(lt);

                setMapper.UseLookupTableScalarRangeOn();
                //setMapper.SetScalarRange(sRange[0], sRange[1]);

                //if (this._contourSetup.ContourLineProperty.IsUseCellRealData)
                //{
                //    setMapper.SetScalarModeToUseCellData ();
                //}
                //else
                //{
                    setMapper.SetScalarModeToUsePointData();
                //}


                //setMapper.SetScalarModeToUsePointData();//总是使用点标量属性数据进行映射，如果没有点标量属性数据则不进行映射
                //setMapper.SetScalarModeToUsePointFieldData();//不使用点或单元的属性数据而是使用点属性数据的一般属性数据来进行映射，该方法应该与ColorByArrayComponent联合使用。
     

                setMapper.ScalarVisibilityOn();//默认打开颜色映射
                //setMapper.ScalarVisibilityOff ();//关闭颜色映射

                vtkActor surfActor;
                //vtkActor surfActor = vtkActor.New();
                if (this._layerActors.Count >= i + 1)
                {
                    surfActor = this._layerActors[i];
                }
                else
                {
                    surfActor = vtkActor.New();
                    this._layerActors.Add(surfActor);
                }


                surfActor.SetMapper(setMapper);
                //surfActor.GetProperty().BackfaceCullingOff();
                //surfActor.GetProperty().EdgeVisibilityOn();

                //surfActor.GetProperty().SetSpecularPower(128);

                surfActor.GetProperty().LightingOff();//如果不关闭，和全局灯光作用导致旋转时颜色忽明忽暗变化；关闭自身的灯光后，旋转不会出现颜色的明暗变化。
                //surfActor.GetProperty().LightingOn();


                //actor.GetProperty().SetInterpolationToFlat();//平滑着色 着色效果较差表现为面片边缘模糊，两个面片相交的边缘出现马赫带。
                surfActor.GetProperty().SetInterpolationToGouraud();//默认 插值平滑着色
                //surfActor.GetProperty().SetInterpolationToPhong();//效果比gouraud好，尤其是由高光的情况，但开销是其6倍左右。
             




                if (this.ContourSetup.ContourLineProperty .ContourFillOrLine  != CONTOURTYPE.Linear && this.ContourSetup.IsContours && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                {
                    this._visiability = true;
                    surfActor.VisibilityOn();
                }
                else
                {
                    this._visiability = false ;
                    surfActor.VisibilityOff();  
                }

                this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(surfActor);




                #endregion


                #region 对网格数据抽取等值线并对等值线着色显示部分




                vtkContourFilter contour;
                //vtkContourFilter contour = vtkContourFilter.New();

                if (this.contourFilter.Count >= i + 1)
                {
                    contour = this.contourFilter[i];
                }
                else
                {
                    contour = vtkContourFilter.New();
                    this.contourFilter.Add(contour);

                }



                //contour.SetInput(layer);
                //contour.SetInput(cTop.GetOutput());
                contour.SetInput(transformFilter .GetOutput ());

                contour.SetNumberOfContours(0);

                if (this.ContourSetup == null)
                {
                    //临时数据
                    contour.SetValue(0, -10);
                    contour.SetValue(1, -5);
                    contour.SetValue(2, 0);
                    contour.SetValue(3, 5);
                    contour.SetValue(4, 10);
                }
                else
                {

                    int num = 0;
                    foreach (double item in this.ContourSetup.DisplayContours.Keys)
                    {
                        contour.SetValue(num, item);
                        num = num + 1;
                    }

                }



                vtkDataSetMapper mapper;
                //vtkDataSetMapper mapper = vtkDataSetMapper.New();

                if (this._contourLineMapper.Count >= i + 1)
                {
                    mapper = this._contourLineMapper[i];
                }
                else
                {
                    mapper = vtkDataSetMapper.New();
                    this._contourLineMapper.Add(mapper);

                }



                mapper.SetInput(contour.GetOutput());

                mapper.SetLookupTable(lt);

                mapper.UseLookupTableScalarRangeOn();
                //mapper.SetScalarRange(sRange[0], sRange[1]);

                //if (this._contourSetup.ContourLineProperty.IsUseCellRealData)
                //{
                //    mapper.SetScalarModeToUseCellData();
                //}
                //else
                //{
                    mapper.SetScalarModeToUsePointData();
                //}
                
                //mapper.SetScalarModeToUsePointFieldData();

                //mapper.SetScalarModeToUseCellData();
                //mapper.SetScalarModeToUseCellFieldData();



                mapper.ScalarVisibilityOn();//默认打开颜色映射


                vtkActor actor;
                //vtkActor actor = vtkActor.New();

                if (this._contourLineActor.Count >= i + 1)
                {
                    actor = this._contourLineActor[i];
                }
                else
                {
                    actor = vtkActor.New();
                    this._contourLineActor.Add(actor);
                }



                actor.SetMapper(mapper);


                //actor.GetProperty().LightingOff();
                //actor.GetProperty().LightingOn();
                

                //actor.GetProperty().SetSpecularPower(128);//灯光，反射等
                //actor.GetProperty().BackfaceCullingOff();



             

                if (this.ContourSetup.ContourLineProperty .ContourFillOrLine  != CONTOURTYPE.Linear )
                {
                   
                    mapper.ScalarVisibilityOff();
                    actor.GetProperty().SetColor(0, 0, 0);
                }
                else
                {
                    mapper.ScalarVisibilityOn();
                }


                //actor.GetProperty().SetInterpolationToFlat();//平滑着色 着色效果较差表现为面片边缘模糊，两个面片相交的边缘出现马赫带。
                actor.GetProperty().SetInterpolationToGouraud();//默认 插值平滑着色
                //actor.GetProperty().SetInterpolationToPhong();//效果比gouraud好，尤其是由高光的情况，但开销是其6倍左右。



                actor.GetProperty().SetLineWidth(this._contourSetup .ContourLineProperty .LineWidth );


                //if (this._repType == REPRESENTATIONTYPE.POINT)
                //{
                //    actor.GetProperty().SetRepresentationToPoints();
                //}
                //else if (this._repType == REPRESENTATIONTYPE.SURFACE)
                //{
                //    actor.GetProperty().SetRepresentationToSurface();
                //}
                //else
                //{
                //    actor.GetProperty().SetRepresentationToWireframe();
                //}



                if (this.ContourSetup.ContourLineProperty .ContourFillOrLine  != CONTOURTYPE.ColorFill  && this.ContourSetup.IsContours && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                {
                    this._visiability = true;
                    actor.VisibilityOn();
                }
                else
                {
                    this._visiability = false;
                    actor.VisibilityOff();
                }
               


                this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(actor);



                #endregion

           

                #endregion

            }//  for (int i = 0; i < this._gridLayers.Count; i++) 结束


            this.CreatePointLabelMask();



            //this.CreateScalarBar();

            //CreateScalarBar02();

            CreateScalarBar03();




        }


        #endregion



        #region  逐层Layer渲染辅助方法


        /// <summary>
        /// 构造网格第i层  点和Cell  以及 CellScalar
        /// 当进行Render的时候调用，因为如果分别调用点和cell的设置方法，会调用两遍For循环，降低效率
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <param name="grid"></param>
        protected void BuildGridLayer(int layerIndex, vtkUnstructuredGrid grid)
        {

            if (grid == null)
            {
                return;
            }
            if (this._contourData == null)
            {
                return;
            }
            if (this._effectiveSign == null)
            {
                return;
            }
            try
            {

                int nCol = this._hg.NCols;//网格边框列方向的边框点个数
                int nRow = this._hg.NRows;//网格边框行方向的边框点个数
                int nPts = nCol * nRow;


                #region 旧的

                //首先取得该层有效单元的个数

                int effectiveCellNumber = 0;

                for (int rows = 0; rows < this.EffectiveSign1[layerIndex].GetLength(0); rows++)
                {
                    for (int cols = 0; cols < this.EffectiveSign1[layerIndex].GetLength(1); cols++)
                    {
                        if (this.EffectiveSign1[layerIndex][rows, cols] != 0)
                        {
                            effectiveCellNumber = effectiveCellNumber + 1;
                        }
                    }
                }

             


                #region 如果有效单元的个数为0

        
                if (effectiveCellNumber <= 0)
                {

                    vtkFloatArray array2 = vtkFloatArray.New();
                    array2.SetNumberOfComponents(3);
                    array2.SetNumberOfTuples(0);//点的个数？？

                    vtkPoints pts2 = vtkPoints.New();
                    pts2.SetData(array2);

                    vtkCellArray cellArray2 = vtkCellArray.New();
                    cellArray2.SetNumberOfCells(0);

                    vtkQuad quad = vtkQuad.New();

                    grid.SetPoints(pts2);
                    grid.SetCells(quad.GetCellType(), cellArray2);



                    return;


                }
                #endregion

                #endregion



                #region 如果有效单元的个数不为0

               if (effectiveCellNumber > 0)
                {
                    //以下为构造数据集

                    #region 构造点集

                    vtkFloatArray array = vtkFloatArray.New();
                    array.SetNumberOfComponents(3);

                    //此处有问题，感觉应该是只添加处于有效单元格的点，而不在任何有效单元格的点不进行添加
                    array.SetNumberOfTuples(nPts);


                    int m = 0;

                    vtkPoints pts = vtkPoints.New();

                    //Coordinate coord;

                    double X = 0;
                    double Y = 0;
                    double Z = 0;


                    //遍历对应Layer的边框上的所有的点
                    for (int i = 0; i < nRow; i++)
                    {
                        for (int j = 0; j < nCol; j++)
                        {

                            //这里需要考虑上下两层的交叉高度

                            //coord = new Coordinate();
                            //coord.X = (this._hg.Coords[i, j, layerIndex].X + this._hg.Coords[i, j, layerIndex + 1].X) / 2;
                            //coord.Y = (this._hg.Coords[i, j, layerIndex].Y + this._hg.Coords[i, j, layerIndex + 1].Y) / 2;
                            //coord.Z = (this._hg.Coords[i, j, layerIndex].Z + this._hg.Coords[i, j, layerIndex + 1].Z) / 2;


                            X = (this._hg.Coords[i, j, layerIndex].X + this._hg.Coords[i, j, layerIndex + 1].X) / 2;
                            Y = (this._hg.Coords[i, j, layerIndex].Y + this._hg.Coords[i, j, layerIndex + 1].Y) / 2;
                            Z = (this._hg.Coords[i, j, layerIndex].Z + this._hg.Coords[i, j, layerIndex + 1].Z) / 2;



                            //问题同上描述，应该只添加位于有效单元格的点

                            //array.SetTuple3(m, coord.X, coord.Y, coord.Z);

                            array.SetTuple3(m, X, Y, Z);

                            m++;

                        }

                    }


                    pts.SetData(array);


                    #endregion


                    #region 构造单元

                    vtkCellArray cellArray = vtkCellArray.New();



                    for (int rows = 0; rows < nRow - 1; rows++)
                    {
                        for (int cols = 0; cols < nCol - 1; cols++)
                        {
                            vtkQuad quadTemp = vtkQuad.New();

                            quadTemp.GetPointIds().SetId(0, (rows + 1) * nCol + cols);
                            quadTemp.GetPointIds().SetId(1, (rows + 1) * nCol + cols + 1);
                            quadTemp.GetPointIds().SetId(2, rows * nCol + cols + 1);
                            quadTemp.GetPointIds().SetId(3, rows * nCol + cols);


                            if (this.EffectiveSign1[layerIndex][rows, cols] != 0)
                            {
                                cellArray.InsertNextCell(quadTemp);

                            }

                            quadTemp.Dispose();

                            quadTemp = null;

                        }

                    }


                    #endregion

                    vtkQuad quad = vtkQuad.New();

                    grid.SetPoints(pts);
                    grid.SetCells(quad.GetCellType(), cellArray);




                }

                #endregion



                #region 新的

                #region 首先生成点的信息

                //vtkFloatArray array = vtkFloatArray.New();
                //array.SetNumberOfComponents(3);
                //array.SetNumberOfTuples(nPts);

                //int m = 0;

                //vtkPoints pts = vtkPoints.New();

                ////Coordinate coord;

                //double X = 0;
                //double Y = 0;
                //double Z = 0;

                ////遍历对应Layer的边框上的所有的点

                //for (int i = 0; i < nRow; i++)
                //{
                //    for (int j = 0; j < nCol; j++)
                //    {
                //        //这里需要考虑上下两层的交叉高度
                //        //coord = new Coordinate();
                //        //coord.X = (this._hg.Coords[i, j, layerIndex].X + this._hg.Coords[i, j, layerIndex + 1].X) / 2;
                //        //coord.Y = (this._hg.Coords[i, j, layerIndex].Y + this._hg.Coords[i, j, layerIndex + 1].Y) / 2;
                //        //coord.Z = (this._hg.Coords[i, j, layerIndex].Z + this._hg.Coords[i, j, layerIndex + 1].Z) / 2;

                //        X = (this._hg.Coords[i, j, layerIndex].X + this._hg.Coords[i, j, layerIndex + 1].X) / 2;
                //        Y = (this._hg.Coords[i, j, layerIndex].Y + this._hg.Coords[i, j, layerIndex + 1].Y) / 2;
                //        Z = (this._hg.Coords[i, j, layerIndex].Z + this._hg.Coords[i, j, layerIndex + 1].Z) / 2;

                //        //array.SetTuple3(m, coord.X, coord.Y, coord.Z);
                //        array.SetTuple3(m, X, Y, Z);

                //        m++;

                //    }

                //}


                //pts.SetData(array);



                #endregion

                //grid.SetPoints(pts);

                #region  生成Cell的信息

                //vtkCellArray cellArray = vtkCellArray.New();

                //m = 0;

                //for (int rows = 0; rows < nRow - 1; rows++)
                //{
                //    for (int cols = 0; cols < nCol - 1; cols++)
                //    {
                //        vtkQuad quadTemp = vtkQuad.New();

                //        quadTemp.GetPointIds().SetId(0, (rows + 1) * nCol + cols);
                //        quadTemp.GetPointIds().SetId(1, (rows + 1) * nCol + cols + 1);
                //        quadTemp.GetPointIds().SetId(2, rows * nCol + cols + 1);
                //        quadTemp.GetPointIds().SetId(3, rows * nCol + cols);


                //        if (this.EffectiveSign1[layerIndex][rows, cols] != 0)
                //        {
                //            cellArray.InsertNextCell(quadTemp);
                //            m++;
                //        }

                //        quadTemp.Dispose();

                //        quadTemp = null;

                //    }

                //}
                //if (m<=0)
                //{
                //    cellArray = vtkCellArray.New();
                //    cellArray.SetNumberOfCells(0);
                //}

                //vtkQuad quad = vtkQuad.New();

                #endregion

                //grid.SetCells(quad.GetCellType(), cellArray);


                //grid.Modified();

                 #endregion 


            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("BuildGridLayer构造网格过程出错！" + e.Message);

                return;
            }



        }


        /// <summary>
        /// 构造网格第i层  Scalar值
        /// 当进行Render的时候调用
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <param name="grid"></param>
        protected void SetGridLayerScalar(int layerIndex, vtkUnstructuredGrid grid)
        {

            if (grid == null)
            {
                return;
            }
            if (this._contourData == null)
            {
                return;
            }
            if (this.EffectiveSign1 == null)
            {
                return;
            }


            try
            {
                if (this._contourData.Count > 0)
                {

                    #region 首先取得对应Layer有效单元的个数

                    //vtkFloatArray scalarValue = vtkFloatArray.New();
                    vtkDoubleArray scalarValue = vtkDoubleArray.New();

                    scalarValue.SetNumberOfComponents(1);

                    //List<double> ps = new List<double>();

                    int cellNum = 0;

                    for (int rows = 0; rows < this.EffectiveSign1[layerIndex].GetLength(0); rows++)
                    {
                        for (int cols = 0; cols < this.EffectiveSign1[layerIndex].GetLength(1); cols++)
                        {
                            if (this.EffectiveSign1[layerIndex][rows, cols] != 0)
                            {

                                scalarValue.InsertNextTuple1(this._contourData[layerIndex][rows, cols]);

                                //ps.Add(this._contourData[layerIndex][rows, cols]);

                                cellNum = cellNum + 1;

                            }
                        }
                    }

                    if (cellNum <= 0)
                    {

                        //grid.GetCellData().Reset();


                        //grid.Modified();

                    }
                    else
                    {

                        //注意：构造Cell的时候和取得添加Scalar值的时候的顺序需保持一致

                        if (grid .GetCellData ()!=null )
                        {
                            grid.GetCellData().SetScalars(scalarValue);
                        }
                      
                        //grid.Modified ();

                    }


                    #endregion
                }
                else
                {
                    //vtkDoubleArray scalarValue = vtkDoubleArray.New();
                    //scalarValue.SetNumberOfComponents(1);
                    //scalarValue.SetNumberOfTuples(0);
                    //grid.GetCellData().SetScalars(scalarValue);

                    grid.GetCellData().Initialize();
                }

                //grid.BuildLinks();


            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("SetGridLayerScalar设置过程出错！");
                return;
            }


        }


       #endregion


        #region 属性改变方法


        /// <summary>
        /// 网格数据（例如高程）改变  ：构造网格点
        /// </summary>
        protected void OnSetHydrolicGrid()
        {

            if (this.ParentNode == null)
            {
                return;

            }

            if (!this.ParentNode.Scene.IsRendering)
            {
                return;

            }


            this._nLayers = this._hg.NLayers - 1;
            this._nRows = this._hg.NRows - 1;
            this._nCols = this._hg.NCols - 1;


            if (this.ContourSetup .ContourMode  == CONTOURMODE.LayerContours)
            {
                //逐层Layer渲染抽取等值线模式

                int index = 0;
                foreach (vtkUnstructuredGrid layer in this._gridLayers)
                {

                    this.SetLayerPoints(index, layer);


                    //this.BuildGridLayer(index, layer);


                    index++;


                }

            }
            else if(this.ContourSetup .ContourMode  ==CONTOURMODE .GridContours )
            {
                //整个网格Grid渲染抽取等值面模式

            
            }




        }


       /// <summary>
       /// 有效单元Cell的标志改变  同时改变该层的Scalar值
       /// </summary>
        protected void OnSetIbound()
        {

            if (this.ParentNode == null)
            {
                return;

            }

            if (!this.ParentNode.Scene.IsRendering)
            {
                return;
            }




            this._nLayers = this._hg.NLayers - 1;
            this._nRows = this._hg.NRows - 1;
            this._nCols = this._hg.NCols - 1;


            int index = 0;
            foreach (vtkUnstructuredGrid layer in this._gridLayers)
            {


                this.SetLayerCellAndScalarData(index, layer);

                index++;

            }



            //this.SetContourCellMinMaxValue();





            //this.OnSetHydrolicGrid();
            //this.OnSetContourData();



        }



        /// <summary>
        /// 单元的Scalar改变
        /// </summary>
        protected void OnSetContourData()
        {

            //在这里需要实现重绘

            if (this.ParentNode == null)
            {
                return;

            }

            if (!this.ParentNode.Scene.IsRendering)
            {
                return;

            }

            //触发Actor可见性的判断更新
            this.OnSetVisibility();


            if (this.ContourSetup .ContourMode  == CONTOURMODE.LayerContours)
            {
                //逐层Layer渲染抽取等值线模式

                int layerIndex = 0;

                foreach (vtkUnstructuredGrid layer in this._gridLayers)
                {

                    this.SetLayerScalarData(layerIndex, layer);
                  

                    #region  旧的方案


                    //List<double> ps = new List<double>();

                    //if (this._contourData.Count > 0)
                    //{
                    //    if (this._contourData.Count == this._effectiveSign.Count)
                    //    {
                    //        for (int rows = 0; rows < this.EffectiveSign1[layerIndex].GetLength(0); rows++)
                    //        {
                    //            for (int cols = 0; cols < this.EffectiveSign1[layerIndex].GetLength(1); cols++)
                    //            {
                    //                if (this.EffectiveSign1[layerIndex][rows, cols] != 0)
                    //                {
                    //                    ps.Add(this._contourData[layerIndex][rows, cols]);
                    //                }
                    //            }
                    //        }
                    //    }
                    //}




                    //if (ps.Count <= 0)
                    //{

                    //    vtkFloatArray scalarValue = vtkFloatArray.New();

                    //    scalarValue.SetNumberOfComponents(1);
                    //    scalarValue.SetNumberOfTuples(0);

                    //    layer.GetCellData().SetScalars(scalarValue);

                    //    layer.Modified();
                    //}
                    //else
                    //{
                    //    vtkFloatArray scalarValue = vtkFloatArray.New();

                    //    scalarValue.SetNumberOfComponents(1);
                    //    scalarValue.SetNumberOfTuples(ps.Count);

                    //    for (int i = 0; i < ps.Count; i++)
                    //    {
                    //        scalarValue.SetTuple1(i, ps[i]);
                    //    }

                    //    //注意：构造Cell的时候和取得添加Scalar值的时候的顺序需保持一致

                    //    layer.GetCellData().SetScalars(scalarValue);

                    //    layer.Modified();

                    //}



                    #endregion


                    layerIndex++;

                }
            }
            else if (this.ContourSetup .ContourMode  == CONTOURMODE.GridContours )
            {
                //整个网格Grid渲染抽取等值面模式
            
            
            }


            //this.SetContourCellMinMaxValue();


        }


        protected void OnSetContourSetup()
        {
            if (this.ParentNode == null)
            {
                return;

            }

            if (!this.ParentNode.Scene.IsRendering)
            {
                return;

            }


            //触发Actor可见性的判断更新
            if (this.ContourSetup.IsContours)
            {
                this.Visiability = true;
            }
            else
            {
                this.Visiability = false;
            }



            //因为目前只是用  Layer  所以此处改变暂时不考虑
            if (this.ContourSetup.ContourMode == CONTOURMODE.LayerContours)
            {
            }
            else
            {
            }


            //更新 Filter 配置   等值线集合，小数点位数
            UpdateLookupTableAndContoourFilter();





        }


        protected void OnSetTransformVector()
        {
            if (this.ParentNode == null)
            {
                return;

            }

            if (!this.ParentNode.Scene.IsRendering)
            {
                return;

            }

            if (this.Transform == null)
            {
                return;
            }

            if (this.Transform != null)
            {
                for (int i = 0; i < this.Transform.Count; i++)
                {
                    if (this.Transform[i] != null)
                    {
                        this.Transform[i].Identity();
                        this.Transform[i].Scale(this.scaleVector.X, this.scaleVector.Y, this.scaleVector.Z);
                    }
                }
            }

        
        }




        #endregion


        #region 内部方法

        /// <summary>
        /// 创建标注
        /// </summary>
        private void CreatePointLabelMask()
        {


            //因为还没有做好  暂时不让进入

            //return;



            if (this._contourSetup.ContourMode == CONTOURMODE.LayerContours)
            {
                if (this._gridLayers == null)
                {
                    return;
                }
                if (this.contourFilter.Count == this._gridLayers.Count)
                {
                    if (this.maskList .Count !=this.contourFilter .Count )
                    {
                        return;
                    }

                    for (int j = 0; j < this.contourFilter.Count; j++)
                    {


                       vtkMaskPoints  mask = this.maskList[j];

                        mask.SetInput(contourFilter[j].GetOutput());

                        //需要在更新 contour 后（如：UpdateLookupTableAndContoourFilter中）更新 mask.SetOnRatio 的配置参数
                        
                        //mask.SetOnRatio(contour.GetOutput().GetNumberOfPoints() / (3 * this.ContourSetup.DisplayContours.Count));
                        //mask.SetOnRatio(495 / (3 * this.ContourSetup.DisplayContours.Count));

                        //mask.SetOnRatio(100 / 50);
                        //mask.SetMaximumNumberOfPoints(50);
                        //mask.SetOnRatio(495 / (3 * this.ContourSetup.DisplayContours.Count));


                        //vtkPolyData polydata = this.contourFilter[j].GetOutput();

                        //polydata.BuildCells();
                        //polydata.BuildLinks(0);
                        //polydata.BuildLinks(1);


                        //int numPoints = this.contourFilter[j].GetOutput().GetNumberOfPoints();
                        //numPoints = this.contourFilter[j].GetOutput().GetNumberOfCells ();
                        //numPoints = this.contourFilter[j].GetOutput().GetNumberOfLines ();



                        //int numPoints = polydata.GetNumberOfPoints();
                        //numPoints = polydata.GetNumberOfCells();
                        //numPoints = polydata.GetNumberOfLines();



                        //vtkRectilinearGrid recGrid = vtkRectilinearGrid.New();
                        //recGrid = this.cTop[0].GetRectilinearGridOutput();

                        //vtkPolyData pdata = vtkPolyData.New();
                        //pdata = this.cTop[0].GetPolyDataOutput ();


                        //vtkContourFilter cFilter = vtkContourFilter.New();
                        ////cFilter .SetInput (_gridLayers [0]);
                        //cFilter.SetInput(recGrid);
                        //cFilter.SetInput(pdata);


                        ////cFilter.SetInputConnection(this._gridLayers[0]);
                        //int num = 0;
                        //foreach (double item in this.ContourSetup.DisplayContours.Keys)
                        //{
                        //    cFilter.SetValue(num, item);
                        //    num = num + 1;
                        //}
                        //numPoints = cFilter.GetOutput().GetNumberOfPoints();
                        //numPoints = cFilter.GetOutput().GetNumberOfCells();
                        //numPoints = cFilter.GetOutput().GetNumberOfLines();
                      




                        mask.SetOnRatio(1);
                       
                        //mask.SetMaximumNumberOfPoints(50);
                        //mask.SetMaximumNumberOfPoints(this.ContourSetup.DisplayContours.Count);
                        
                        mask.SetMaximumNumberOfPoints(this.ContourSetup.Tagging .MaskPointNum );



                        mask.SetOffset(1);
            


                        mask.RandomModeOn();

                        //选取可视点

                        //vtkSelectVisiblePoints visPts = visPtsList[j];
                        //visPts.SetInputConnection(mask.GetOutputPort());
                        //visPts.SetRenderer(this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer());

                   
                      //  visPts.SelectionWindowOn();
                      //  //visPts.SetSelection(1,100,1,100);



                        //ldm = vtkLabeledDataMapper.New();
                        vtkLabeledDataMapper ldm = ldmList[j];

                        ldm.SetInputConnection(mask.GetOutputPort());
                        //ldm.SetInputConnection(visPts.GetOutputPort());
                        //ldm.SetInput(contour.GetOutput());

                        //ldm.SetLabelFormat("%2g");

                        if (this._contourSetup.ContourLineProperty.IsUseScientificNotation)
                        {
                            string labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "E";
                            ldm.SetLabelFormat(labelFormat);
                        }
                        else
                        {
                            string labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                            //string labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "g";
                            ldm.SetLabelFormat(labelFormat);
                        
                        }

                        //if (this._contourSetup.ContourLineProperty.IsSpecifyPrecision)
                        //{
                            //string labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                            //string labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "g";
                            //ldm.SetLabelFormat(labelFormat);
                            //ldm.SetLabelFormat("%1.1g");
                        //}
                        //else
                        //{
                        //    string labelFormat = "%1.15f";
                        //    //string labelFormat = "%1.15g";

                        //    ldm.SetLabelFormat(labelFormat);

                        //    //ldm.SetLabelFormat("%1.1g");
                        //}
                      


                        ldm.SetLabelModeToLabelScalars();

                        ldm.GetLabelTextProperty().SetFontFamilyToArial();

                        ldm.GetLabelTextProperty().SetFontSize(this._contourSetup .Tagging .FontSize );

                        ldm.GetLabelTextProperty().SetColor(this._contourSetup.Tagging.TagColor.R / 255.0, this._contourSetup.Tagging.TagColor.G / 255.0, this._contourSetup.Tagging.TagColor.B / 255.0);
                        //ldm.GetLabelTextProperty().SetColor(1,0,0);

                        ldm.GetLabelTextProperty().SetJustificationToCentered();
                        //ldm.GetLabelTextProperty().SetJustificationToCentered();

                        //ldm.GetLabelTextProperty().SetLineSpacing();
                   




                        //vtkActor2D contourLabels = vtkActor2D.New();
                        vtkActor2D contourLabels = contourLabelsList[j];
                        contourLabels.SetMapper(ldm);


                        if (this._contourSetup.Tagging.IsShowTagging  == true && this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                        {

                            contourLabels.VisibilityOn();

                        }
                        else 
                        {
                            contourLabels.VisibilityOff ();
                        }


                        //vtkActor2D pointLabels=vtkActor2D .New ();
                        //pointLabels.SetMapper(ldm);

                        //vtkPolyDataMapper contMapper=vtkPolyDataMapper .New ();
                        //contMapper.SetInputConnection(contour.GetOutputPort ());
                        //contMapper .SetScalarRange( 0, 250);
                        //vtkActor contActor=vtkActor .New ();
                        //contActor.SetMapper(contMapper);

                        //this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(contActor);


                        this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(contourLabels);


                       


                    }

                }

            }
            else
            {


            }






            #region 尝试分别给每层的等值线添加标注

            //if (i == 0)
            {
                //首先 以第一层做尝试

                #region 尝试添加标注


                //vtkTextActor textActor2d;


                //vtkTextActor3D textActor3d;


                //vtkTextSource textSource;





                #endregion


                #region  尝试添加标注

                //int numpts = contour.GetOutput().GetNumberOfCells();//为啥全是 0 ？？
                //int numpts2 = contour.GetOutput().GetNumberOfLines();
                //int numpts3 = contour.GetOutput().GetNumberOfPoints();


                //int a = contour.GetNumberOfContours();
                //int b = contour.GetOutput().GetNumberOfVerts();





                //mask = vtkMaskPoints.New();

                //mask.SetInput(contour.GetOutput());

                ////需要在更新 contour 后（如：UpdateLookupTableAndContoourFilter中）更新 mask.SetOnRatio 的配置参数
                ////mask.SetOnRatio(contour.GetOutput().GetNumberOfPoints() / (3 * this.ContourSetup.DisplayContours.Count));
                //mask.SetOnRatio(495 / (3 * this.ContourSetup.DisplayContours.Count));
                ////mask.SetMaximumNumberOfPoints(50);
                //mask.SetMaximumNumberOfPoints(3 * this.ContourSetup.DisplayContours.Count);

                ////double aa = mask.GetOnRatio();


                ////mask.SetOnRatio(100 / 50);
                ////mask.SetMaximumNumberOfPoints(50);



                //mask.RandomModeOn();

                ////选取可视点

                //visPts = vtkSelectVisiblePoints.New();
                //visPts.SetInputConnection(mask.GetOutputPort());
                //visPts.SetRenderer(this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer());

                //visPts.SelectionWindowOn();
                ////visPts.SetSelection(1,100,1,100);



                //ldm = vtkLabeledDataMapper.New();

                //ldm.SetInputConnection(mask.GetOutputPort());
                ////ldm.SetInputConnection(visPts.GetOutputPort());
                ////ldm.SetInput(contour.GetOutput());

                ////ldm.SetLabelFormat("%2g");
                //ldm.SetLabelFormat("%g");
                //ldm.SetLabelModeToLabelScalars();
                //ldm.GetLabelTextProperty().SetFontFamilyToArial();
                //ldm.GetLabelTextProperty().SetFontSize(10);
                //ldm.GetLabelTextProperty().SetColor(1, 0, 0);
                //ldm.GetLabelTextProperty().SetJustificationToCentered();


                //contourLabels = vtkActor2D.New();
                //contourLabels.SetMapper(ldm);
                //contourLabels.VisibilityOn();


                //this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(contourLabels);


                #region  成功了7成  哈哈


                //ldm = vtkLabeledDataMapper.New();

                ////ldm.SetInputConnection(mask.GetOutputPort());
                ////ldm.SetInputConnection(visPts.GetOutputPort());
                //ldm.SetInput(contour.GetOutput());

                ////ldm.SetLabelFormat("%2g");
                //ldm.SetLabelFormat("%g");
                //ldm.SetLabelModeToLabelScalars();
                ////ldm.GetLabelTextProperty().SetFontFamilyToArial();
                ////ldm.GetLabelTextProperty().SetFontSize(10);
                ////ldm.GetLabelTextProperty().SetColor(1, 0, 0);
                ////ldm.GetLabelTextProperty().SetJustificationToCentered();


                //vtkActor2D pointLabels=vtkActor2D .New ();
                //pointLabels.SetMapper(ldm);

                //vtkPolyDataMapper contMapper=vtkPolyDataMapper .New ();
                //contMapper.SetInputConnection(contour.GetOutputPort ());
                //contMapper .SetScalarRange( 0, 250);
                //vtkActor contActor=vtkActor .New ();
                //contActor.SetMapper(contMapper);



                //this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(pointLabels);
                //this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(contActor);

                #endregion



                #endregion


            }

            #endregion

        
        
        }



        /// <summary>
        /// 创建图例  只有scalarBarActor，属性控制位置大小
        /// </summary>
        private void CreateScalarBar()
        {



            //return; //因为还没有做好  暂时不让进入

            //还需要更加细致的调节


            if (this.scalarBarActor == null)
            {
                this.scalarBarActor = vtkScalarBarActor.New();
            }

            //if (this.scalarBarWidget ==null )
            //{
            //    this.scalarBarWidget = vtkScalarBarWidget.New();
            //}

            if (this._contourSetup.ContourMode == CONTOURMODE.LayerContours)
            {


                #region 添加图例ScalarBar  网格的所有层共同使用


                if (this._layerLookupTable == null)
                {
                    return;
                }

                if (this._layerLookupTable.Count > 0)
                {

                    //所有各层的配置相同  故采用第一层的参数即可

                    vtkDiscretizableColorTransferFunction lt = this._layerLookupTable[0];


                    #region ColorLegend 尝试

                    //vtkScalarBarRepresentation reper = vtkScalarBarRepresentation.New();
                    //vtkContext2D contest2d = vtkContext2D.New();
                    //vtkPen pen = vtkPen.New();
                    //vtkTextProperty textProperty = vtkTextProperty.New();
                    ////vtkPlot plot = vtkPlot.New();
                    //vtkBrush brush = vtkBrush.New();
                    ////vtkStdString stdString=vtkstdstring               
                    //vtkTransform2D transform2d = vtkTransform2D.New();

                    ////vtkChart chart= vtkChart.New  ();
                    //////chart .ClearPlots ();
                    ////chart.SetShowLegend (true );
                    ////chart.SetTitle("Data");
                    ////chart.SetVisible(true);
                    //////chart.Paint();
                    //vtkChartLegend chartLegend = vtkChartLegend.New();
                    ////chartLegend.SetChart(chart); 
                    ////chartLegend .
                    ////vtkcolor
                    //vtkLegendScaleActor legendScaleActor = vtkLegendScaleActor.New();
                    ////legendScaleActor .seten
                    ////legendScaleActor.VisibilityOn();
                    ////this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(legendScaleActor);
                    //vtkLegendBoxActor boxActor = vtkLegendBoxActor.New();                   
                    ////boxActor .set
                    ////boxActor.VisibilityOn();
                    ////                    vtkSmartPointer<vtkLegendBoxActor> legend = 
                    ////  vtkSmartPointer<vtkLegendBoxActor>::New();
                    ////legend->SetNumberOfEntries(2);
                    ////double color[3] = {1,0,0};
                    ////legend->SetEntry(0, static_cast<vtkPolyData *> (NULL), "test", color);
                    ////vtkSmartPointer<vtkSphereSource> legendSphereSource = 
                    ////  vtkSmartPointer<vtkSphereSource>::New();
                    ////vtkSmartPointer<vtkPolyData> legendSphere = legendSphereSource->GetOutput();
                    ////legend->SetEntry(1, legendSphere, "test", color);

                    ////this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(boxActor);

                    ////return;


                    #endregion

                    #region

                    //vtkTextProperty labelProperty = vtkTextProperty.New();
                    //scalarBarActor.SetLabelTextProperty(labelProperty);

                    //vtkTextMapper labelMapper = vtkTextMapper.New();

                    //vtkTextProperty titleProperty = vtkTextProperty.New();
                    //scalarBarActor.SetTitleTextProperty(titleProperty);

                    //vtkTextMapper titleMapper = vtkTextMapper.New();
                    ////titleMapper.SetInput();
                    //vtkActor2D titleActor = vtkActor2D.New();


                    //vtkLookupTable lut = vtkLookupTable.New();
                    //scalarBarActor.SetLookupTable(lut);


                    //vtkPolyDataMapper2D mapper2d = vtkPolyDataMapper2D.New();
                    //scalarBarActor.SetMapper(mapper2d );



                    //vtkProperty2D property2d=vtkProperty2D .New ();
                    //scalarBarActor.SetProperty(property2d );



                    //scalarBarActor.SetLayerNumber(5);

                    //scalarBarActor.SetNumberOfLabels(5);


                    // vtkScalarsToColors LookupTable = null;
                    // vtkCoordinate Position2Coordinate = vtkCoordinate.New();
                    // Position2Coordinate.SetValue (0.17, 0.8);

                    // vtkCoordinate PositionCoordinate = vtkCoordinate.New();
                    // PositionCoordinate.SetCoordinateSystemToNormalizedViewport();
                    // PositionCoordinate.SetValue(0.82, 0.1);


                    // //this->MaximumNumberOfColors = 64;
                    // //this->NumberOfLabels = 5;
                    // //this->NumberOfLabelsBuilt = 0;
                    // //this->Orientation = VTK_ORIENT_VERTICAL;
                    // //this->Title = NULL;
                    // //this->ComponentTitle = NULL;

                    // vtkTextProperty LabelTextProperty = vtkTextProperty.New();
                    // LabelTextProperty.SetFontSize(12);
                    // LabelTextProperty.SetBold(1);
                    // LabelTextProperty.SetItalic(1);
                    // LabelTextProperty.SetShadow(1);
                    // LabelTextProperty.SetFontFamilyToArial();

                    // vtkTextProperty TitleTextProperty = vtkTextProperty.New();
                    //TitleTextProperty.ShallowCopy(LabelTextProperty);

                    //vtkTextMapper TitleMapper = vtkTextMapper.New();

                    //vtkActor2D TitleActor = vtkActor2D.New();
                    // //vtkWindow win=vtkWindow .New ();
                    // //TitleActor .ReleaseGraphicsResources (vtkWindow win);



                    //vtkPolyData ScalarBar = vtkPolyData.New();

                    //vtkPolyDataMapper2D ScalarBarMapper = vtkPolyDataMapper2D.New();

                    //vtkActor2D ScalarBarActor = vtkActor2D.New();


                    //vtkPolyData TexturePolyData = vtkPolyData.New();
                    //vtkPolyDataMapper2D textureMapper = vtkPolyDataMapper2D.New();

                    // textureMapper.SetInput(TexturePolyData);
                    // vtkActor2D TextureActor = vtkActor2D.New();
                    // TextureActor.SetMapper(textureMapper);

                    // vtkFloatArray tc = vtkFloatArray.New();
                    // tc.SetNumberOfComponents(2);
                    // tc.SetNumberOfTuples(4);
                    // tc.InsertComponent(0,0, 0.0);  
                    // tc.InsertComponent(0,1, 0.0);
                    // tc.InsertComponent(1,1, 0.0);
                    // tc.InsertComponent(3,0, 0.0);  
                    // TexturePolyData.GetPointData().SetTCoords(tc);

                    // vtkCellArray polys2 = vtkCellArray.New ();
                    //   polys2.InsertNextCell(4);
                    //   polys2.InsertCellPoint(0);
                    //   polys2.InsertCellPoint(1);
                    //   polys2.InsertCellPoint(2);
                    //   polys2.InsertCellPoint(3);
                    //   TexturePolyData.SetPolys(polys2);


                    //   vtkProperty2D imageProperty = vtkProperty2D.New ();
                    //   imageProperty.SetOpacity(0.08);
                    //   TextureActor.SetProperty(imageProperty);

                    //   // Create the default texture. Just a "Jail" like grid

                    //   int dim = 128;
                    //   vtkImageData image = vtkImageData.New();
                    //   image.SetDimensions(dim, dim, 1);
                    //   image.SetScalarTypeToUnsignedChar();
                    //   image.AllocateScalars();

                    //   for ( int y = 0; y < dim; y++)
                    //     {
                    //      char *ptr = 
                    //       static_cast< unsigned char * >(image.GetScalarPointer(0, y, 0));
                    //     for (unsigned int x = 0; x < dim; x++)
                    //       {
                    //       *ptr = ((x == y) || (x == (dim-y-1))) ? 255 : 0;
                    //       ++ptr;
                    //       }
                    //     }

                    //  vtkTexture Texture = vtkTexture.New();
                    //   Texture.SetInput( image );
                    //   Texture.RepeatOn();


                    //   // Default text position : Above scalar bar if orientation is horizontal
                    //   //                         Right of scalar bar if orientation is vertical
                    //   TextPosition = SucceedScalarBar;

                    //   MaximumWidthInPixels = VTK_INT_MAX;
                    //   MaximumHeightInPixels = VTK_INT_MAX;



                    #endregion



                    #region scalarBarActor  成功7成

                    //scalarBarActor.SetTitle(this._contourSetup .ScalarBar .Title );//该 Title 应该由外部传递
                    //scalarBarActor.SetTitle("");//该 Title 应该由外部传递
                    scalarBarActor.SetLookupTable(lt);
                    scalarBarActor.SetNumberOfLabels(lt.GetNumberOfValues());



                    //scalarBarActor.SetOrientationToHorizontal();//查询表的方向  垂直还是横向等
                    scalarBarActor.SetOrientationToVertical();//竖直



                    //关于坐标系
                    //Display      vtkRenderWindow  x_y  Pixel   the origin  is  the  lower_left  corner 
                    //Normalized    Display   x_y  (0,1)
                    //ViewPort     x_y  pixel  vtkRender/vtkViewPort
                    //Normalized Viewport    x_y (0,1) viewPort
                    //View          x_y_z (-1,1)  camera coordinates
                    //World         x_y_z  global coordinate
                    //UserDefined   x_y_z



                    //scalarBarActor.GetPositionCoordinate().SetCoordinateSystemToDisplay  ();//设置坐标系  配合设置位置坐标使用
                    scalarBarActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay();//0-1   x  y  缩放


                    //scalarBarActor.GetPositionCoordinate().SetCoordinateSystemToViewport();//pixels   x y    不缩放
                    //scalarBarActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport();//  0-1  x  y  缩放



                    //scalarBarActor.GetPosition2Coordinate().SetCoordinateSystemToDisplay();//(0,1)
                    //scalarBarActor.GetPosition2Coordinate().SetCoordinateSystemToNormalizedDisplay();//(0,1)
                    //scalarBarActor.GetPosition2Coordinate().SetCoordinateSystemToNormalizedViewport();//(0,1)
                    //scalarBarActor.GetPosition2Coordinate().SetCoordinateSystemToView();//(-1,1)
                    //scalarBarActor.GetPosition2Coordinate().SetCoordinateSystemToViewport();
                    //scalarBarActor.GetPosition2Coordinate().SetCoordinateSystemToWorld();



                    //scalarBarActor.GetPositionCoordinate().SetValue(0.93, 0.25);          

                    scalarBarActor.GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);

                        scalarBarActor.SetWidth(this._contourSetup.ScalarBar.Width);//占窗口的比例  1 为全部
                        scalarBarActor.SetHeight(this._contourSetup.ScalarBar.Height);//占窗口的比例  1 为全部

               


                    //%g具体含义，“自动使用%e和%f两者中格式化后位数最短的形式来转换显示”
                    //1、当传入的浮点数的有效数字不超过6位时，使用“%g”能够有效的去除浮点数显示时小数点后面多余的0，并且当因误差而出现多个“9”的形式时，能够自动进位，得到与实际的浮点数一致的显示效果；
                    //2、当传入的浮点数的有效数字超过6位时，自动将数据显示为科学计数的形式，即使用“%e”的格式化形式；


                    if (this._contourSetup.ContourLineProperty.IsUseScientificNotation)
                    {
                        string labelFormat = "%-#2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "E";
                        scalarBarActor.SetLabelFormat(labelFormat);

                    }
                    else
                    {
                        string labelFormat = "%-#2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                        scalarBarActor.SetLabelFormat(labelFormat);
                    }



                    //scalarBarActor.SetLabelFormat("%1.3g");        
                    //scalarBarActor.SetLabelFormat("%2.2f");//f 表示标题和label 同规则          
                    //scalarBarActor.SetLabelFormat("%-#6.5f");


                    //scalarBarActor.GetLabelTextProperty().SetFontSize(1);//为啥不起作用？？？
                    scalarBarActor.GetLabelTextProperty().SetFontSize(this._contourSetup.ScalarBar.LabelFontSize);//为啥不起作用？？？



                    //scalarBarActor.GetLabelTextProperty().BoldOff();
                    scalarBarActor.GetLabelTextProperty().SetJustificationToCentered();//位置相关    //为啥不起作用？？？
                    //scalarBarActor.GetLabelTextProperty().SetJustificationToLeft ();//位置相关
                    //scalarBarActor.GetLabelTextProperty().SetJustificationToRight  ();//位置相关


                    scalarBarActor.GetLabelTextProperty().SetVerticalJustificationToCentered();//label中的数字相互对齐方式  垂直方向      //为啥不起作用？？？
                    //scalarBarActor.GetLabelTextProperty().SetVerticalJustificationToTop ();//label中的数字
                    //scalarBarActor.GetLabelTextProperty().SetVerticalJustificationToBottom ();//label中的数字

                    //scalarBarActor.GetLabelTextProperty().SetLineSpacing(0.01);//两个Label之间的距离

                    //scalarBarActor.GetLabelTextProperty().SetFontFamilyAsString ();//啥意思？？
                    scalarBarActor.GetLabelTextProperty().SetFontFamilyToTimes();
                    scalarBarActor.GetLabelTextProperty().SetBold(1);



                    scalarBarActor.GetLabelTextProperty().SetOpacity(1);

                    //scalarBarActor.GetLabelTextProperty().SetColor(1.0,1.0,1.0);//黑色
                    //scalarBarActor.GetLabelTextProperty().SetColor(1.0, 0, 0);//红色

                    //颜色
                    scalarBarActor.GetLabelTextProperty().SetColor(this._contourSetup.ScalarBar.LabelColor.R / 255.0, this._contourSetup.ScalarBar.LabelColor.G / 255.0, this._contourSetup.ScalarBar.LabelColor.B / 255.0);



                    //scalarBarActor.GetLabelTextProperty ().ShadowOff();//不显示Label标注


                    //想要不显示图例标题，并且标题不占用设置的图例高度
                    //scalarBarActor.SetTitle("data");
                    //scalarBarActor.GetTitleTextProperty().SetFontSize(1);//设置标题最小化 ， 因为暂时主程序要求不显示标题，设置图例高度时，标题高度会对位置产生影响
                    scalarBarActor.GetTitleTextProperty().ShadowOff();//不显示Title文字
                    //scalarBarActor.GetTitleTextProperty().GetFontFamilyAsString();//啥意思？？

                    //double lineSpacing = scalarBarActor.GetTitleTextProperty().GetLineSpacing();
                    //double lineOffset = scalarBarActor.GetTitleTextProperty().GetLineOffset ();                

                    //scalarBarActor.GetTitleTextProperty().SetLineOffset (0);
                    //scalarBarActor.GetTitleTextProperty().SetLineSpacing (0);

                    //scalarBarActor.SetTextPositionToPrecedeScalarBar();//如果是竖直，title在下侧，如果是横向，title在左侧
                    //scalarBarActor.SetTextPositionToSucceedScalarBar();
                    //scalarBarActor.SetUseBounds(false );




                    //scalarBarActor.GetTextureActor().PickableOn ();
                    //scalarBarActor.GetTextureActor().SetDisplayPosition();
                    //scalarBarActor.GetTextureActor().GetProperty().SetDisplayLocation();


                    //scalarBarActor.GetTextureActor().GetProperty().SetLineStipplePattern (1);
                    //scalarBarActor.GetTextureActor().GetProperty().SetLineWidth (2);



                    //double width=     scalarBarActor.GetTextureGridWidth();


                    scalarBarActor.PickableOn();//是否允许选择？？？ 不管用呀
                    scalarBarActor.DragableOn();//是否允许拖拽？？  不管用呀
                    scalarBarActor.Pick();
                    scalarBarActor.UseOpacityOn();




                    //scalarBarActor.PickableOff ();//是否允许选择？？？
                    //scalarBarActor.DragableOff ();//是否允许拖拽？？
                    ////scalarBarActor.Pick();
                    //scalarBarActor.UseOpacityOn();

                    //if (this._contourSetup .ScalarBar .IsDragable ==false && this._contourSetup.ScalarBar.IsShowScalarBar == true && this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                  if ( this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                    {
                           scalarBarActor.VisibilityOn();

                    }
                    else
                    {
                        scalarBarActor.VisibilityOff();
                    }


                    ////scalarBarActor.GetProperty().SetLineStipplePattern(0);


                    #endregion

                    //if (scalarBarWidget==null )
                    //{
                    //    scalarBarWidget = vtkScalarBarWidget.New();
                    //}
                   

                    #region scalarBarWidget  不使用

                    //scalarBarWidget.SetCurrentRenderer(this.ParentNode.Scene.VtkRenderer);
                    //scalarBarWidget.SetInteractor(this.ParentNode.Scene.VtkInteractor);
                    //scalarBarWidget.SetScalarBarActor(scalarBarActor);


                    //if (this._contourSetup.ScalarBar.IsDragable)
                    //{
                    //    scalarBarWidget.RepositionableOn();//移动
                    //    scalarBarWidget.ResizableOn();//大小
                    //}
                    //else
                    //{
                    //    scalarBarWidget.RepositionableOff();//移动
                    //    scalarBarWidget.ResizableOff();//大小
                    //}


                    //scalarBarWidget.Modified();

                    //scalarBarWidget.SetEnabled(1);
                    //scalarBarWidget.SetSelectable(0);
                  

                    //if (this._contourSetup .ScalarBar .IsDragable ==true &&  this._contourSetup.ScalarBar.IsShowScalarBar == true && this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                    //{
                    //    scalarBarWidget.On();//可见性
                    //}
                    //else
                    //{
                    //    scalarBarWidget.Off();

                    //}
                


                    #endregion


                    this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(scalarBarActor);

                    //this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor2D(scalarBarActor);

                }


                #endregion



            }
            else
            {



            }




        }

        /// <summary>
        /// 创建图例  既有scalarBarActor，属性控制位置大小；又有scalarBarWidget，拖动控制
        /// </summary>
        private void CreateScalarBar02()
        {

            //return; //因为还没有做好  暂时不让进入

            //还需要更加细致的调节

            //actor和widget共存，属性控制时使用actor，拖动时使用widget


            if (this.scalarBarActor == null)
            {
                this.scalarBarActor = vtkScalarBarActor.New();
            }

            if (this.scalarBarWidget == null)
            {
                this.scalarBarWidget = vtkScalarBarWidget.New();
            }

            if (this._contourSetup.ContourMode == CONTOURMODE.LayerContours)
            {


                #region 添加图例ScalarBar  网格的所有层共同使用


                if (this._layerLookupTable == null)
                {
                    return;
                }

                if (this._layerLookupTable.Count > 0)
                {

                    //所有各层的配置相同  故采用第一层的参数即可

                    vtkDiscretizableColorTransferFunction lt = this._layerLookupTable[0];


                    #region scalarBarActor  成功7成

                    if (scalarBarWidget == null)
                    {
                        scalarBarWidget = vtkScalarBarWidget.New();
                    }
                    //scalarBarWidget.SetCurrentRenderer(this.ParentNode.Scene.VtkRenderer);

                    scalarBarWidget.SetInteractor(this.ParentNode.Scene.VtkInteractor);//交互,其内部是添加众多和交互操作（例如鼠标单击，移动等）的时间订阅观察者

                    scalarBarWidget.SetScalarBarActor(this.scalarBarActor );
                                                


                    #region

                    scalarBarWidget.GetScalarBarActor().SetLookupTable(lt);
                    scalarBarWidget.GetScalarBarActor().SetNumberOfLabels(lt.GetNumberOfValues());

                    //scalarBarActor.SetOrientationToHorizontal();//查询表的方向  垂直还是横向等
                    scalarBarWidget.GetScalarBarActor().SetOrientationToVertical();//竖直


                    //关于坐标系
                    //Display      vtkRenderWindow  x_y  Pixel   the origin  is  the  lower_left  corner 
                    //Normalized    Display   x_y  (0,1)
                    //ViewPort     x_y  pixel  vtkRender/vtkViewPort
                    //Normalized Viewport    x_y (0,1) viewPort
                    //View          x_y_z (-1,1)  camera coordinates
                    //World         x_y_z  global coordinate
                    //UserDefined   x_y_z


                    scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay();//0-1   x  y  缩放
                    
                    scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);


                    scalarBarWidget.GetScalarBarActor().SetWidth(this._contourSetup.ScalarBar.Width);//占窗口的比例  1 为全部
                    scalarBarWidget.GetScalarBarActor().SetHeight(this._contourSetup.ScalarBar.Height);//占窗口的比例  1 为全部

            

                    //%g具体含义，“自动使用%e和%f两者中格式化后位数最短的形式来转换显示”
                    //1、当传入的浮点数的有效数字不超过6位时，使用“%g”能够有效的去除浮点数显示时小数点后面多余的0，并且当因误差而出现多个“9”的形式时，能够自动进位，得到与实际的浮点数一致的显示效果；
                    //2、当传入的浮点数的有效数字超过6位时，自动将数据显示为科学计数的形式，即使用“%e”的格式化形式；


                    if (this._contourSetup.ContourLineProperty.IsUseScientificNotation)
                    {
                        string labelFormat = "%-#2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "E";
                        scalarBarWidget.GetScalarBarActor().SetLabelFormat(labelFormat);

                    }
                    else
                    {
                        string labelFormat = "%-#2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                        scalarBarWidget.GetScalarBarActor().SetLabelFormat(labelFormat);
                    }

                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetFontSize(this._contourSetup.ScalarBar.LabelFontSize);//为啥不起作用？？？
                    
      
                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetJustificationToCentered();//位置相关    //为啥不起作用？？？
                    //scalarBarActor.GetLabelTextProperty().SetJustificationToLeft ();//位置相关
      
                    
                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetVerticalJustificationToCentered();//label中的数字相互对齐方式  垂直方向      //为啥不起作用？？？
                   
                    //scalarBarActor.GetLabelTextProperty().SetLineSpacing(0.01);//两个Label之间的距离

                    //scalarBarActor.GetLabelTextProperty().SetFontFamilyAsString ();//啥意思？？
                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetFontFamilyToTimes();
                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetBold(1);

                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetOpacity(1);    

                    //颜色
                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetColor(this._contourSetup.ScalarBar.LabelColor.R / 255.0, this._contourSetup.ScalarBar.LabelColor.G / 255.0, this._contourSetup.ScalarBar.LabelColor.B / 255.0);

                    scalarBarWidget.GetScalarBarActor().GetTitleTextProperty().ShadowOff();//不显示Title文字
              
            
                    //scalarBarActor.SetTextPositionToPrecedeScalarBar();//如果是竖直，title在下侧，如果是横向，title在左侧
                    //scalarBarActor.SetTextPositionToSucceedScalarBar();

                    #endregion

                    //     Set/Get the pickable instance variable. This determines if the vtkProp can
                    //     be picked (typically using the mouse). Also see dragable.  Initial value
                    //     is true.

                    //scalarBarWidget.GetScalarBarActor().PickableOn();//是否允许选择？？？ 不管用呀
                    //scalarBarWidget.GetScalarBarActor().PickableOff ();//是否允许选择？？？ 不管用呀

                    //     Set/Get the value of the dragable instance variable. This determines if an
                    //     Prop, once picked, can be dragged (translated) through space.  This is typically
                    //     done through an interactive mouse interface.  This does not affect methods
                    //     such as SetPosition, which will continue to work. It is just intended to
                    //     prevent some vtkProp'ss from being dragged from within a user interface.
                    //      Initial value is true.

                    //scalarBarWidget.GetScalarBarActor().DragableOn();//是否允许拖拽？？  不管用呀  
                    //scalarBarWidget.GetScalarBarActor().DragableOff ();

                    //scalarBarWidget.GetScalarBarActor().UseOpacityOn();
                    //scalarBarWidget.GetScalarBarActor().UseOpacityOff ();



                    //if (this._contourSetup.ScalarBar.IsDragable == false && this._contourSetup.ScalarBar.IsShowScalarBar == true && this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                    //{
                    //    scalarBarWidget.GetScalarBarActor().VisibilityOn();

                    //}
                    //else
                    //{
                    //    scalarBarWidget.GetScalarBarActor().VisibilityOff();
                    //}




                    #endregion




                    if (this._contourSetup.ScalarBar.IsDragable)
                    {
                        #region    actor和widget  共存  问题：由actor转widget时，widget的位置无法控制

                        scalarBarWidget.SetEnabled(1);

                        scalarBarWidget.SelectableOff();

                        scalarBarWidget.On();


                        scalarBarWidget.RepositionableOn();//移动
                        scalarBarWidget.ResizableOn();//大小

                        #endregion



                    }
                    else
                    {
                        #region  actor和widget  共存  问题：由actor转widget时，widget的位置无法控制

                        scalarBarWidget.SetEnabled(0);

                        scalarBarWidget.SelectableOff();

                        scalarBarWidget.Off();


                        scalarBarWidget.RepositionableOff();//移动
                        scalarBarWidget.ResizableOff();//大小

                        #endregion

                        #region

                        //scalarBarWidget.SetEnabled(1);

                        //scalarBarWidget.SelectableOff();

                        //scalarBarWidget.Off();


                        //scalarBarWidget.RepositionableOff();//移动
                        //scalarBarWidget.ResizableOff();//大小

                        #endregion

                    }




                    if ( this._contourSetup.ScalarBar.IsShowScalarBar == true && this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                    {
                        scalarBarWidget.GetScalarBarActor().VisibilityOn ();
                        //scalarBarWidget.On();//Methods for turning the interactor observer on and off

                    }
                    else
                    {
                        scalarBarWidget.GetScalarBarActor().VisibilityOff ();
                        //scalarBarWidget.Off();//Methods for turning the interactor observer on and off
                        scalarBarWidget.SetEnabled(0);             

                    }

                    //添加显示actor    widget是通过Interactor设置添加的，是否使用通过Enabled设置
                    this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(this.scalarBarWidget.GetScalarBarActor());

                    scalarBarWidget.GetScalarBarActor().Modified();
                    
                    scalarBarWidget.Modified();


                }


                #endregion



            }
            else
            {



            }
        
        }

        /// <summary>
        /// 创建图例  只有scalarBarWidget，拖动控制
        /// </summary>
        private void CreateScalarBar03()
        {

            //return; //因为还没有做好  暂时不让进入

            //还需要更加细致的调节

            //actor和widget共存，属性控制时使用actor，拖动时使用widget


            if (this.scalarBarActor == null)
            {
                this.scalarBarActor = vtkScalarBarActor.New();
            }

            if (this.scalarBarWidget == null)
            {
                this.scalarBarWidget = vtkScalarBarWidget.New();
            }

            if (this._contourSetup.ContourMode == CONTOURMODE.LayerContours)
            {


                #region 添加图例ScalarBar  网格的所有层共同使用


                if (this._layerLookupTable == null)
                {
                    return;
                }

                if (this._layerLookupTable.Count > 0)
                {

                    //所有各层的配置相同  故采用第一层的参数即可

                    vtkDiscretizableColorTransferFunction lt = this._layerLookupTable[0];


                    #region scalarBarActor  成功7成

                    if (scalarBarWidget == null)
                    {
                        scalarBarWidget = vtkScalarBarWidget.New();
                    }
                    //scalarBarWidget.SetCurrentRenderer(this.ParentNode.Scene.VtkRenderer);

                    scalarBarWidget.SetInteractor(this.ParentNode.Scene.VtkInteractor);//交互,其内部是添加众多和交互操作（例如鼠标单击，移动等）的时间订阅观察者

                    //scalarBarWidget.SetScalarBarActor(this.scalarBarActor);



                    #region

                    scalarBarWidget.GetScalarBarActor().SetLookupTable(lt);
                    scalarBarWidget.GetScalarBarActor().SetNumberOfLabels(lt.GetNumberOfValues());

                    //scalarBarActor.SetOrientationToHorizontal();//查询表的方向  垂直还是横向等
                    scalarBarWidget.GetScalarBarActor().SetOrientationToVertical();//竖直


                    //关于坐标系
                    //Display      vtkRenderWindow  x_y  Pixel   the origin  is  the  lower_left  corner 
                    //Normalized    Display   x_y  (0,1)
                    //ViewPort     x_y  pixel  vtkRender/vtkViewPort
                    //Normalized Viewport    x_y (0,1) viewPort
                    //View          x_y_z (-1,1)  camera coordinates
                    //World         x_y_z  global coordinate
                    //UserDefined   x_y_z


                    scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay();//0-1   x  y  缩放

                    scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);


                    scalarBarWidget.GetScalarBarActor().SetWidth(this._contourSetup.ScalarBar.Width);//占窗口的比例  1 为全部
                    scalarBarWidget.GetScalarBarActor().SetHeight(this._contourSetup.ScalarBar.Height);//占窗口的比例  1 为全部



                    //%g具体含义，“自动使用%e和%f两者中格式化后位数最短的形式来转换显示”
                    //1、当传入的浮点数的有效数字不超过6位时，使用“%g”能够有效的去除浮点数显示时小数点后面多余的0，并且当因误差而出现多个“9”的形式时，能够自动进位，得到与实际的浮点数一致的显示效果；
                    //2、当传入的浮点数的有效数字超过6位时，自动将数据显示为科学计数的形式，即使用“%e”的格式化形式；


                    if (this._contourSetup.ContourLineProperty.IsUseScientificNotation)
                    {
                        string labelFormat = "%-#2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "E";
                        scalarBarWidget.GetScalarBarActor().SetLabelFormat(labelFormat);

                    }
                    else
                    {
                        string labelFormat = "%-#2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                        scalarBarWidget.GetScalarBarActor().SetLabelFormat(labelFormat);
                    }

                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetFontSize(this._contourSetup.ScalarBar.LabelFontSize);//为啥不起作用？？？


                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetJustificationToCentered();//位置相关    //为啥不起作用？？？
                    //scalarBarActor.GetLabelTextProperty().SetJustificationToLeft ();//位置相关


                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetVerticalJustificationToCentered();//label中的数字相互对齐方式  垂直方向      //为啥不起作用？？？

                    //scalarBarActor.GetLabelTextProperty().SetLineSpacing(0.01);//两个Label之间的距离

                    //scalarBarActor.GetLabelTextProperty().SetFontFamilyAsString ();//啥意思？？
                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetFontFamilyToTimes();
                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetBold(1);

                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetOpacity(1);

                    //颜色
                    scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetColor(this._contourSetup.ScalarBar.LabelColor.R / 255.0, this._contourSetup.ScalarBar.LabelColor.G / 255.0, this._contourSetup.ScalarBar.LabelColor.B / 255.0);

                    scalarBarWidget.GetScalarBarActor().GetTitleTextProperty().ShadowOff();//不显示Title文字


                    //scalarBarActor.SetTextPositionToPrecedeScalarBar();//如果是竖直，title在下侧，如果是横向，title在左侧
                    //scalarBarActor.SetTextPositionToSucceedScalarBar();

                    #endregion

                    //     Set/Get the pickable instance variable. This determines if the vtkProp can
                    //     be picked (typically using the mouse). Also see dragable.  Initial value
                    //     is true.

                    //scalarBarWidget.GetScalarBarActor().PickableOn();//是否允许选择？？？ 不管用呀
                    //scalarBarWidget.GetScalarBarActor().PickableOff ();//是否允许选择？？？ 不管用呀

                    //     Set/Get the value of the dragable instance variable. This determines if an
                    //     Prop, once picked, can be dragged (translated) through space.  This is typically
                    //     done through an interactive mouse interface.  This does not affect methods
                    //     such as SetPosition, which will continue to work. It is just intended to
                    //     prevent some vtkProp'ss from being dragged from within a user interface.
                    //      Initial value is true.

                    //scalarBarWidget.GetScalarBarActor().DragableOn();//是否允许拖拽？？  不管用呀  
                    //scalarBarWidget.GetScalarBarActor().DragableOff ();

                    //scalarBarWidget.GetScalarBarActor().UseOpacityOn();
                    //scalarBarWidget.GetScalarBarActor().UseOpacityOff ();



                    //if (this._contourSetup.ScalarBar.IsDragable == false && this._contourSetup.ScalarBar.IsShowScalarBar == true && this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                    //{
                    //    scalarBarWidget.GetScalarBarActor().VisibilityOn();

                    //}
                    //else
                    //{
                    //    scalarBarWidget.GetScalarBarActor().VisibilityOff();
                    //}




                    #endregion



                    //始终允许拖动

                    //if (this._contourSetup.ScalarBar.IsDragable)
                    //{
                        #region    actor和widget  共存  问题：由actor转widget时，widget的位置无法控制

                        scalarBarWidget.SetEnabled(1);

                        scalarBarWidget.SelectableOff();

                        scalarBarWidget.On();


                        scalarBarWidget.RepositionableOn();//移动
                        scalarBarWidget.ResizableOn();//大小

                        #endregion



                    //}
                    //else
                    //{
                    //    #region  actor和widget  共存  问题：由actor转widget时，widget的位置无法控制

                    //    scalarBarWidget.SetEnabled(1);

                    //    scalarBarWidget.SelectableOff();

                    //    scalarBarWidget.Off();


                    //    scalarBarWidget.RepositionableOff();//移动
                    //    scalarBarWidget.ResizableOff();//大小

                    //    #endregion

                    //    #region

                    //    //scalarBarWidget.SetEnabled(1);

                    //    //scalarBarWidget.SelectableOff();

                    //    //scalarBarWidget.Off();


                    //    //scalarBarWidget.RepositionableOff();//移动
                    //    //scalarBarWidget.ResizableOff();//大小

                    //    #endregion

                    //}




                    if (this._contourSetup.ScalarBar.IsShowScalarBar == true && this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                    {
                        scalarBarWidget.GetScalarBarActor().VisibilityOn();
                        //scalarBarWidget.On();//Methods for turning the interactor observer on and off
                        scalarBarWidget.SetEnabled(1);

                    }
                    else
                    {
                        scalarBarWidget.GetScalarBarActor().VisibilityOff();
                        //scalarBarWidget.Off();//Methods for turning the interactor observer on and off
                        scalarBarWidget.SetEnabled(0);

                    }

                    //添加显示actor    widget是通过Interactor设置添加的，是否使用通过Enabled设置
                    //this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(this.scalarBarWidget.GetScalarBarActor());

                    scalarBarWidget.GetScalarBarActor().Modified();

                    scalarBarWidget.Modified();


                }


                #endregion



            }
            else
            {



            }
        
        }


        #region 未使用

        /// <summary>
        /// 当ContourData或者有效单元改变后  重新配置Cell的 MinMax 等信息
        /// </summary>
        protected void SetContourCellMinMaxValue()
        {

            //double[] minMax = this.GetMinMaxContourData();

            //foreach (vtkDataSetMapper item in this._layerMappers)
            //{
            //    item.SetScalarRange(minMax[0], minMax[1]);

            //}
            ////foreach (vtkColorTransferFunction item in this._layerLookupTable)
            //foreach (vtkDiscretizableColorTransferFunction item in this._layerLookupTable)
            //{
            //    if (item != null)
            //    {
            //        item.SetRange(minMax[0], minMax[1]);
            //    }
            //}

        }


        protected void RefreshView()
        {

        }

        /// <summary>
        /// 取得数据的最大最小值
        /// </summary>
        /// <returns></returns>
        //protected double[] GetMinMaxContourData()
        //{

        //    double min = double.MaxValue;

        //    double max = double.MinValue;


        //    double[] value = new double[2];


        //    #region

        //    if (this._contourSetup == null)
        //    {
        //        min = 0.0;
        //        max = 0.0;
        //    }
        //    else
        //    {
        //        min = this._contourSetup.ScalarRangeMin;
        //        max = this._contourSetup.ScalarRangeMax;
        //    }


        //    #endregion


        //    value[0] = min;
        //    value[1] = max;


        //    return value;


        //}

        // /// <summary>
        // /// 取得新的Scalar值
        // /// </summary>
        // private void GetNewHeadCellScalars()
        // {

        //     if (this.EffectiveSign == null||this._headScalar==null)
        //     {
        //         return;
        //     }
        //     if (this.scalars ==null )
        //     {
        //         return;
        //     }
        //     this.scalars = vtkFloatArray.New();
        //     this.SetCellScalarsValue(this.scalars);


        // }
        //   /// <summary>
        ///// 设置Scalars
        ///// </summary>
        ///// <param name="scalars"></param>
        // protected void SetCellScalarsValue(vtkFloatArray scalars)
        // {

        //     try
        //     {
        //         //该地方需要注意的问题：假设某个点无效  怎样存储的它的Scalar值  怎样设置 scalars.SetNumberOfTuples   scalars.SetTuple1

        //         scalars.SetNumberOfComponents(1);

        //         //int pointNum = this._headScalar.Count * this._headScalar[0].GetLength(0) * this._headScalar[0].GetLength(1);
        //         //scalars.SetNumberOfTuples(pointNum);//边框点个数

        //         List<double> ps = new List<double>();

        //         //double[] ps = new double[pointNum];
        //         //int index = 0;

        //         for (int layer = 0; layer < this._headScalar.Count; layer++)
        //         {
        //             for (int rows = 0; rows < this._headScalar[layer].GetLength(0); rows++)
        //             {
        //                 for (int cols = 0; cols < this._headScalar[layer].GetLength(1); cols++)
        //                 {
        //                     if (this.EffectiveSign[layer][rows, cols]!= 0)
        //                     {
        //                         ps.Add(this._headScalar[layer][rows, cols]);

        //                         //ps[index] = this._headScalar[layer][rows, cols];
        //                         //ps[index] = cols * 0.1;
        //                         //index += 1;

        //                     }
        //                     else
        //                     {

        //                     }
        //                 }
        //             }
        //         }

        //         scalars.SetNumberOfTuples(ps.Count);

        //         for (int i = 0; i < ps.Count; i++)
        //         {
        //             scalars.SetTuple1(i, ps[i]);
        //         }



        //         _unGrid.GetCellData().SetScalars(scalars);



        //         //添加一般属性数据 用来对等值面进行颜色映射
        //         //因为如果使用使用标量值scalars由于等值面上各处的标量值相同所以着色后，颜色单一


        //         aArray = vtkFloatArray.New();
        //         aArray.SetName("aArray");

        //         int index = 0;

        //         for (int layer = 0; layer < this._headScalar.Count; layer++)
        //         {
        //             for (int rows = 0; rows < this._headScalar[layer].GetLength(0); rows++)
        //             {
        //                 for (int cols = 0; cols < this._headScalar[layer].GetLength(1); cols++)
        //                 {
        //                     if (this.EffectiveSign[layer][rows, cols] != 0)
        //                     {
        //                         aArray.InsertNextTuple1(index);
        //                         index += 1;
        //                     }
        //                     else
        //                     {

        //                     }
        //                 }
        //             }
        //         }


        //         _unGrid.GetCellData().AddArray(aArray);






        //     }
        //     catch (Exception)
        //     {
        //         System.Windows.Forms.MessageBox.Show("ContourFilter设置Scalar值过程出错！");
        //         return;
        //     }


        // }

        #endregion



        /// <summary>
        /// 该方法被抛弃 未使用
        /// </summary>
        protected void RenderGridContour()
        {


            #region 抽取等值面  并给等值面进行着色


            // 使用标量数据产生等值面。


            #region 抽取等值面 输入参数是 vtkUnstructuredGrid   contourGrid = vtkContourGrid.New();  哈哈 找得我好苦呀


            //contourGrid = this.ParentNode.Scene.ContourParameter.GetNewContourGridFilter();
            contourGrid = null;

            if (contourGrid == null)
            {
                contourGrid = vtkContourGrid.New();

                contourGrid.SetNumberOfContours(5);

                contourGrid.SetValue(0, 10.44);
                contourGrid.SetValue(1, 20.88);
                contourGrid.SetValue(2, 31.33);
                contourGrid.SetValue(3, 41.77);
                contourGrid.SetValue(4, 52.21);


            }

            contourGrid.SetInput(_unGrid);


            #endregion


            #region 抽取等值线   iso = vtkContourFilter.New();


            //iso = vtkContourFilter.New();

            //iso = this.ParentNode.Scene.ContourParameter.GetNewContourFilter();


            if (iso == null)
            {
                iso = vtkContourFilter.New();

                //iso.SetValue(0, 0);
                //iso.SetValue(1, 2.5);
                //iso.SetValue(2, 5);
                //iso.SetValue(3, 7.5);
                //iso.SetValue(4, 10);


                iso.SetValue(0, 46.667);
                iso.SetValue(1, 83.333);
                iso.SetValue(2, 125);
                iso.SetValue(3, 166.667);
                iso.SetValue(4, 208.333);


                //iso.GenerateValues(5, 0, 10);

            }


            iso.SetInput(_unGrid);
            //iso.SetInput(cTop .GetOutput ());

            //iso.ComputeScalarsOn();

            //iso.SetArrayComponent(0);

            #endregion



            contourNormals = vtkPolyDataNormals.New();

            contourNormals.SetInputConnection(contourGrid.GetOutputPort());
            //contourNormals.SetInputConnection(iso.GetOutputPort ());
            contourNormals.SetFeatureAngle(45);


            //指定映射器使用一般属性数组，该数据数组
            //是单元属性数据中的一部分。


            isoMapper = vtkDataSetMapper.New();

            //isoMapper.SetInput(iso.GetOutput());
            isoMapper.SetInput(contourNormals.GetOutput());


            #region 同等值面单一着色


            //lut = vtkLookupTable.New();
            //lut = this.ParentNode.Scene.LookUpTable.GetNewLookupTable();

            if (lut == null)
            {

                lut = vtkLookupTable.New();
                //设置色调范围（红到蓝）
                lut.SetHueRange(0.667, 1);
                //设置饱和度范围
                lut.SetSaturationRange(1, 1);
                lut.SetValueRange(1, 1);
                lut.SetNumberOfColors(256);

                //lut.SetTableRange(0, 10);
                //lut.SetNumberOfTableValues(5);

                lut.SetTableRange(0, 250);
                lut.SetNumberOfTableValues(6);


                lut.Build();

            }



            isoMapper.SetLookupTable(lut);
            isoMapper.SetScalarRange(lut.GetTableRange()[0], lut.GetTableRange()[1]);
            //isoMapper.SetScalarRange(contourNormals.GetOutput().GetScalarRange()[0], contourNormals.GetOutput().GetScalarRange()[1]);

            //isoMapper.SetScalarModeToDefault ();
            isoMapper.SetScalarModeToUsePointData();
            //isoMapper.SetScalarModeToUseCellData();


            if (this._contourType == CONTOURTYPE.Linear)
            {
                isoMapper.ScalarVisibilityOn();
            }
            else if (this._contourType == CONTOURTYPE.ColorFill)
            {
                isoMapper.ScalarVisibilityOff();
            }
            else
            {
                isoMapper.ScalarVisibilityOn();
            }




            //isoMapper.SetInput(this._unGrid );
            //isoMapper.SetInputConnection (iso.GetOutputPort ());
            //isoMapper.SetInput(contourNormals.GetOutput());
            //isoMapper.ScalarVisibilityOff();

            #endregion  等值面着色结束


            //此处关键是如何给等值面进行着色  分为同一等值面单一着色和同一等值面不同着色

            #region  同等值面不同着色

            //isoMapper.SetScalarModeToUsePointFieldData();//映射模式 和设置颜色有关
            //isoMapper.ColorByArrayComponent("aArray", 0);

            #endregion


            isoActor = vtkActor.New();
            isoActor.SetMapper(isoMapper);

            if (this._repType == REPRESENTATIONTYPE.POINT)
            {
                isoActor.GetProperty().SetRepresentationToPoints();
            }
            else if (this._repType == REPRESENTATIONTYPE.SURFACE)
            {
                isoActor.GetProperty().SetRepresentationToSurface();
            }
            else if (this._repType == REPRESENTATIONTYPE.WIREFRAME)
            {
                isoActor.GetProperty().SetRepresentationToWireframe();
            }


            //isoActor.GetProperty().SetColor(0.1,1,0.2);


            //isoActor.SetScale(1,1,10);


            isoActor.VisibilityOn();
            //isoActor.VisibilityOff();


            this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(isoActor);



            #endregion



            #region 外围边框  未使用

            //mapper = vtkDataSetMapper.New();
            //mapper.SetInput(_unGrid);

            ////mapper.SetScalarModeToUseCellFieldData();
            ////mapper.SetScalarModeToUseFieldData();


            //isoActor = vtkActor.New();
            //isoActor.SetMapper(mapper);
            //isoActor.VisibilityOn();
            //this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(isoActor);


            #endregion

            #region 功能Filter 参考 未使用


            //int i;

            //double[] x = { -2, -6, -7, -9 };

            //double[] y = { -1, -3, -4, -5 };

            //double[] z = { 0, 4, 7, 9 };


            //// 定义三组分别沿x、y、z轴上的坐标。
            //xCoords = vtkDoubleArray.New();
            //for (i = 0; i < 4; i++) xCoords.InsertNextValue(x[i]);

            //yCoords = vtkDoubleArray.New();
            //for (i = 0; i < 4; i++) yCoords.InsertNextValue(y[i]);

            //zCoords = vtkDoubleArray.New();
            //for (i = 0; i < 4; i++) zCoords.InsertNextValue(z[i]);

            ////Double[] ps ={0.8,0.5,0.8,0.6,0.7,0.8,0.5,0.6,0.8,0.7,0.8,0.6,0.7,0.6,0.5,0.7,
            ////        0.8,0.5,0.6,0.6,0.7,0.5,0.6,0.7,0.8,0.6,0.7,0.8,0.8,0.8,0.8,0.7,
            ////        0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.6,
            ////        0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.6,
            ////        };



            //int n = zCoords.GetNumberOfTuples();// 数量是 4
            //rgrids = new List<vtkRectilinearGrid>();
            //isolines = new List<vtkContourFilter>();
            //isolineMappers = new List<vtkPolyDataMapper>();
            //isolineActors = new List<vtkActor>();
            //for (i = 0; i < n; i++)
            //{
            //    rgrids.Add(vtkRectilinearGrid.New());//每层构建新网格  共 4 层
            //    rgrids[i].SetDimensions(4, 4, 1);

            //    rgrids[i].SetXCoordinates(xCoords);
            //    rgrids[i].SetYCoordinates(yCoords);

            //    vtkDoubleArray zCoord = vtkDoubleArray.New();
            //    zCoord.InsertNextValue(z[i]);
            //    rgrids[i].SetZCoordinates(zCoord);

            //    zCoord.Dispose();
            //    //标量属性
            //    vtkFloatArray scalar = vtkFloatArray.New();
            //    scalar.SetNumberOfTuples(16);//每层有  16  个点
            //    for (int j = 0; j < 16; j++)
            //    {
            //        scalar.SetTuple1(j, ps[i * 16 + j]);//每个点设置Scalar值
            //    }
            //    rgrids[i].GetPointData().SetScalars(scalar);
            //    scalar.Dispose();
            //    //等值线

            //    isolines.Add(vtkContourFilter.New());
            //    isolines[i].SetInput(rgrids[i]);//设置数据集
            //    isolines[i].GenerateValues(4, 0.5, 0.8);//抽取等值线的范围
            //    isolines[i].Update();
            //    //等值线映射器

            //    isolineMappers.Add(vtkPolyDataMapper.New());
            //    isolineMappers[i].SetInputConnection(isolines[i].GetOutputPort());

            //    //演员(等值线)

            //    isolineActors.Add(vtkActor.New());
            //    isolineActors[i].SetMapper(isolineMappers[i]);
            //    //isolineActors[i].GetProperty().SetColor(0,0,0);


            //}
            //int numpts = isolines[0].GetOutput().GetNumberOfPoints();


            //for (i = 0; i < isolineActors.Count(); i++)
            //{
            //    this.ParentNode.Scene.VtkControl.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(isolineActors[i]);
            //    //ren1.AddActor(isolineActors[i]);

            //}

            #endregion




        }



        #region  point和Cell分离处理


        /// <summary>
        /// 设置指定Layer的Points
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <param name="grid"></param>
        protected void SetLayerPoints(int layerIndex, vtkUnstructuredGrid grid)
        {
            if (grid == null)
            {
                return;
            }
            if (this._contourData == null)
            {
                return;
            }
            if (this._effectiveSign == null)
            {
                return;
            }

            try
            {


                //改变Points信息  不要关心Cell的有效性

                int nCol = this._hg.NCols;//网格边框列方向的边框点个数
                int nRow = this._hg.NRows;//网格边框行方向的边框点个数
                int nPts = nCol * nRow;



                //以下为构造数据集

                #region 构造点集

                vtkFloatArray array = vtkFloatArray.New();
                array.SetNumberOfComponents(3);
                array.SetNumberOfTuples(nPts );


                int m = 0;



                vtkPoints pts = vtkPoints.New();

                //Coordinate coord;

                double X, Y, Z;


                //遍历对应Layer的边框上的所有的点
                for (int i = 0; i < nRow; i++)
                {
                    for (int j = 0; j < nCol; j++)
                    {

                        //这里需要考虑上下两层的交叉高度

                        //coord = new Coordinate();

                        //coord.X = (this._hg.Coords[i, j, layerIndex].X + this._hg.Coords[i, j, layerIndex + 1].X) / 2;
                        //coord.Y = (this._hg.Coords[i, j, layerIndex].Y + this._hg.Coords[i, j, layerIndex + 1].Y) / 2;
                        //coord.Z = (this._hg.Coords[i, j, layerIndex].Z + this._hg.Coords[i, j, layerIndex + 1].Z) / 2;


                        //array.InsertNextTuple4 (m, coord.X, coord.Y, coord.Z);




                        X = (this._hg.Coords[i, j, layerIndex].X + this._hg.Coords[i, j, layerIndex + 1].X) / 2;
                        Y = (this._hg.Coords[i, j, layerIndex].Y + this._hg.Coords[i, j, layerIndex + 1].Y) / 2;
                        Z = (this._hg.Coords[i, j, layerIndex].Z + this._hg.Coords[i, j, layerIndex + 1].Z) / 2;



                        array.SetTuple3 (m, X, Y, Z);
                        //array.InsertNextTuple4(m, X, Y, Z);



                        m++;

                    }

                }


                pts.SetData(array);


                #endregion


                grid.SetPoints(pts);

                grid.Modified();//Update the modification time for this object. Many filters rely on the modification time to determine if they need to recompute their data. The modification time is a unique monotonically increasing unsigned long integer. 




            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("构造网格的点集合的过程出错！" + e.Message);

                return;
            }

        }


        /// <summary>
        /// 单独设置指定Layer的Cell
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <param name="grid"></param>
        protected void SetLayerCells(int layerIndex, vtkUnstructuredGrid grid)
        {
            if (grid == null)
            {
                return;
            }
            if (this._contourData == null)
            {
                return;
            }
            if (this._effectiveSign == null)
            {
                return;
            }

            try
            {

                int nCol = this._hg.NCols;//网格边框列方向的边框点个数
                int nRow = this._hg.NRows;//网格边框行方向的边框点个数
                int nPts = nCol * nRow;



                //以下为构造数据集

                #region 构造单元

                vtkCellArray cellArray = vtkCellArray.New();

                vtkQuad quadTemp = vtkQuad.New();

                for (int rows = 0; rows < nRow - 1; rows++)
                {
                    for (int cols = 0; cols < nCol - 1; cols++)
                    {
                         //quadTemp = vtkQuad.New();

                        quadTemp.GetPointIds().SetId(0, (rows + 1) * nCol + cols);
                        quadTemp.GetPointIds().SetId(1, (rows + 1) * nCol + cols + 1);
                        quadTemp.GetPointIds().SetId(2, rows * nCol + cols + 1);
                        quadTemp.GetPointIds().SetId(3, rows * nCol + cols);


                        if (this.EffectiveSign1[layerIndex][rows, cols] != 0)
                        {
                            cellArray.InsertNextCell(quadTemp);

                        }

                        //quadTemp.Dispose();
                        //quadTemp = null;

                    }

                }



                #endregion

                if (quadTemp ==null )
                {
                    quadTemp = vtkQuad.New();
                }

                grid.SetCells(quadTemp.GetCellType(), cellArray);

                grid.Modified();


                if (quadTemp !=null )
                {
                    quadTemp.Dispose();
                    quadTemp = null;
                }


            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("SetLayerCells设置过程出错！" + e.Message);

                return;
            }

        }


        /// <summary>
        /// 单独设置指定Layer的ScalarData
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <param name="grid"></param>
        protected void SetLayerScalarData(int layerIndex, vtkUnstructuredGrid grid)
        {

            if (grid == null)
            {
                return;
            }
            if (this._contourData == null)
            {
                return;
            }
            if (this.EffectiveSign1 == null)
            {
                return;
            }


            try
            {
                
                    #region 首先取得对应Layer有效单元的个数

                    //List<double> ps = new List<double>();

                    vtkFloatArray scalarValue = vtkFloatArray.New();

                    scalarValue.SetNumberOfComponents(1);

                    int m = 0;

                    if (this._contourData.Count > 0)
                    {
                        if (this._contourData.Count == this._effectiveSign.Count)
                        {
                            for (int rows = 0; rows < this.EffectiveSign1[layerIndex].GetLength(0); rows++)
                            {
                                for (int cols = 0; cols < this.EffectiveSign1[layerIndex].GetLength(1); cols++)
                                {
                                    if (this.EffectiveSign1[layerIndex][rows, cols] != 0)
                                    {

                                        //ps.Add(this._contourData[layerIndex][rows, cols]);

                                        scalarValue.InsertNextTuple1(this._contourData[layerIndex][rows, cols]);

                                        //scalarValue.InsertNextTuple2 (m, this._contourData[layerIndex][rows, cols]);

                                        m = m + 1;

                                    }

                                }
                            }
                        }
                    }


                    if (m <= 0)
                    {

                        //grid.GetCellData().Reset();

                        //    vtkPoints points = grid.GetPoints();
                        //    vtkCellArray cellArray = grid.GetCells();

                        //    grid = vtkUnstructuredGrid.New();
                        //    grid.SetPoints(points);

                        //    vtkQuad quadTemp = vtkQuad.New();

                        //    grid.SetCells(quadTemp.GetCellType(), cellArray);

                        grid.GetCellData().Initialize();

                    }
                    else
                    {

                        grid.GetCellData().SetScalars(scalarValue);//GetCellData()方法，当不存在时自动返回一个新建立的实例


                        grid.Modified();

                    }

                    //grid.BuildLinks();


                    #endregion


                    #region 设置单元的scalar值


                    //if (ps.Count <= 0)
                    //{

                    //    vtkFloatArray scalarValue = vtkFloatArray.New();

                    //    scalarValue.SetNumberOfComponents(1);
                    //    scalarValue.SetNumberOfTuples(0);

                    //    grid.GetCellData().SetScalars(scalarValue);

                    //    grid.Modified();
                    //}
                    //else
                    //{
                    //    vtkFloatArray scalarValue = vtkFloatArray.New();

                    //    scalarValue.SetNumberOfComponents(1);
                    //    scalarValue.SetNumberOfTuples(ps.Count);

                    //    for (int i = 0; i < ps.Count; i++)
                    //    {
                    //        scalarValue.SetTuple1(i, ps[i]);
                    //    }

                    //    //注意：构造Cell的时候和取得添加Scalar值的时候的顺序需保持一致

                    //    grid.GetCellData().SetScalars(scalarValue);

                    //    grid.Modified();

                    //}


                    #endregion

            

            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("SetLayerScalarData设置过程出错！");
                return;
            }

        }


        /// <summary>
        /// 同时改变Cell和Scalar  供改变EffectiveCell时调用
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <param name="grid"></param>
        protected void SetLayerCellAndScalarData(int layerIndex, vtkUnstructuredGrid grid)
        {

            if (grid == null)
            {
                return;
            }
            if (this._contourData == null)
            {
                return;
            }
            if (this._effectiveSign == null)
            {
                return;
            }

            try
            {



                //只改变Cell和Scalar  不要关心Points点的情况


                int nCol = this._hg.NCols;//网格边框列方向的边框点个数
                int nRow = this._hg.NRows;//网格边框行方向的边框点个数
                int nPts = nCol * nRow;





                //以下为构造数据集

                #region 构造单元

                vtkCellArray cellArray = vtkCellArray.New();


                vtkDoubleArray scalarValue = vtkDoubleArray.New();
                //vtkFloatArray scalarValue = vtkFloatArray.New();
                scalarValue.SetNumberOfComponents(1);


                int cellNum = 0;

                //vtkQuad quadTemp = null;
                vtkQuad quadTemp = new vtkQuad();

                for (int rows = 0; rows < nRow - 1; rows++)
                {
                    for (int cols = 0; cols < nCol - 1; cols++)
                    {
                        //vtkQuad quadTemp = new vtkQuad();
                        //quadTemp = vtkQuad.New();

                        quadTemp.GetPointIds().SetId(0, (rows + 1) * nCol + cols);
                        quadTemp.GetPointIds().SetId(1, (rows + 1) * nCol + cols + 1);
                        quadTemp.GetPointIds().SetId(2, rows * nCol + cols + 1);
                        quadTemp.GetPointIds().SetId(3, rows * nCol + cols);


                        if (this.EffectiveSign1[layerIndex][rows, cols] != 0)
                        {
                            if (this._contourData.Count > 0)
                            {
                                scalarValue.InsertNextTuple1(this._contourData[layerIndex][rows, cols]);
                                //scalarValue.InsertNextTuple2(  m  , this._contourData[layerIndex][rows, cols]);
                            }

                            cellArray.InsertNextCell(quadTemp);


                            cellNum = cellNum + 1;

                        }

                        //quadTemp.Dispose();
                        //quadTemp = null;


                    }

                }



                #endregion

                if (quadTemp == null)
                {
                    quadTemp = vtkQuad.New();
                }

                if (cellNum <= 0)
                {
                    cellArray = vtkCellArray.New();

                    cellArray.SetNumberOfCells(0);

                    //scalarValue = vtkFloatArray.New();
                    //scalarValue.SetNumberOfComponents(1);
                    //scalarValue.SetNumberOfTuples(0);
                    //grid.GetCellData().Dispose();
                    //grid.GetCellData().SetScalars (scalarValue);


                    grid.GetCellData().Reset();
                    grid.GetCellData().Initialize();//释放内存



                    grid.SetCells(quadTemp.GetCellType(), cellArray);

                }
                else
                {

                    grid.GetCellData().Initialize();//释放内存
                    //grid.GetCells().Initialize();



                    grid.SetCells(quadTemp.GetCellType(), cellArray);//该方法将重写以前存储在vtkCellArray中的所有信息，所以所有和这些cells相关的变成无效的


                    if (this._contourData.Count > 0)
                    {
                        grid.GetCellData().SetScalars(scalarValue);//（继承自vtkDataSetAttributes）vtkCellData.SetScalars()设置活动有效的ScalarArray
                    }
                    //else
                    //{
                    //    grid.GetCellData().Initialize();
                    //}

                }

                //grid.Modified();
                grid.BuildLinks();


                //if (quadTemp != null)
                //{
                //    quadTemp.Dispose();
                //    quadTemp = null;
                //}




            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("SetLayerCellAndScalarData设置过程出错！" + e.Message);

                return;
            }




        }



        /// <summary>
        /// 该方法暂时未调试好。。。。。。。。。
        /// 同时改变Point Cell Scalar  供Render时调用
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <param name="grid"></param>
        protected void BuildLayerPointCellScalar(int layerIndex, vtkUnstructuredGrid grid)
        {


            if (grid == null)
            {
                return;
            }
            if (this._contourData == null)
            {
                return;
            }
            if (this._effectiveSign == null)
            {
                return;
            }

            try
            {

                int nCol = this._hg.NCols;//网格边框列方向的边框点个数
                int nRow = this._hg.NRows;//网格边框行方向的边框点个数
                int nPts = nCol * nRow;




                #region 首先取得该层有效单元的个数

                //int effectiveCellNumber = 0;

                //for (int rows = 0; rows < this.EffectiveSign1[layerIndex].GetLength(0); rows++)
                //{
                //    for (int cols = 0; cols < this.EffectiveSign1[layerIndex].GetLength(1); cols++)
                //    {
                //        if (this.EffectiveSign1[layerIndex][rows, cols] != 0)
                //        {
                //            effectiveCellNumber = effectiveCellNumber + 1;
                //        }
                //    }
                //}

                #endregion


                #region 如果有效单元的个数为0

                //if (effectiveCellNumber <= 0)
                //{

                //    vtkFloatArray array2 = vtkFloatArray.New();
                //    array2.SetNumberOfComponents(3);
                //    array2.SetNumberOfTuples(0);//点的个数？？

                //    vtkPoints pts2 = vtkPoints.New();
                //    pts2.SetData(array2);

                //    vtkCellArray cellArray2 = vtkCellArray.New();
                //    cellArray2.SetNumberOfCells(0);

                //    vtkQuad quad = vtkQuad.New();

                //    grid.SetPoints(pts2);
                //    grid.SetCells(quad.GetCellType(), cellArray2);


                //    return;


                //}

                #endregion


                #region 如果有效单元的个数不为0




                //if (effectiveCellNumber > 0)
                {

                    #region 构造

                    vtkFloatArray array = vtkFloatArray.New();

                    array.SetNumberOfComponents(3);


                    int m = 0;


                    vtkPoints pts = vtkPoints.New();

                    vtkCellArray cellArray = vtkCellArray.New();

                    //Coordinate coord;
                    double X, Y, Z;


                    vtkFloatArray scalarValue = vtkFloatArray.New();
                    scalarValue.SetNumberOfComponents(1);


                    //遍历对应Layer的边框上的所有的点
                    for (int i = 0; i < nRow; i++)
                    {
                        for (int j = 0; j < nCol; j++)
                        {

                            //这里需要考虑上下两层的交叉高度

                            //coord = new Coordinate();

                            //coord.X = (this._hg.Coords[i, j, layerIndex].X + this._hg.Coords[i, j, layerIndex + 1].X) / 2;
                            //coord.Y = (this._hg.Coords[i, j, layerIndex].Y + this._hg.Coords[i, j, layerIndex + 1].Y) / 2;
                            //coord.Z = (this._hg.Coords[i, j, layerIndex].Z + this._hg.Coords[i, j, layerIndex + 1].Z) / 2;

                            //array.InsertNextTuple4(m, coord.X, coord.Y, coord.Z);


                            X = (this._hg.Coords[i, j, layerIndex].X + this._hg.Coords[i, j, layerIndex + 1].X) / 2;
                            Y = (this._hg.Coords[i, j, layerIndex].Y + this._hg.Coords[i, j, layerIndex + 1].Y) / 2;
                            Z = (this._hg.Coords[i, j, layerIndex].Z + this._hg.Coords[i, j, layerIndex + 1].Z) / 2;

                            array.InsertNextTuple4(m, X, Y, Z);


                            m++;


                            if (layerIndex <= NLayers - 2)
                            {
                                if (i <= nRow - 2)
                                {
                                    if (j <= nCol - 2)
                                    {

                                        vtkQuad quadTemp = vtkQuad.New();

                                        quadTemp.GetPointIds().SetId(0, (i + 1) * nCol + j);
                                        quadTemp.GetPointIds().SetId(1, (i + 1) * nCol + j + 1);
                                        quadTemp.GetPointIds().SetId(2, i * nCol + j + 1);
                                        quadTemp.GetPointIds().SetId(3, i * nCol + j);


                                        if (this.EffectiveSign1[layerIndex][i, j] != 0)
                                        {
                                            scalarValue.InsertNextTuple1(this._contourData[layerIndex][i, j]);

                                            //ps.Add(this._contourData[layerIndex][i, j]);

                                            cellArray.InsertNextCell(quadTemp);

                                        }
                                        quadTemp.Dispose();
                                    }
                                }
                            }

                        }
                    }
                    //cellArray.SetNumberOfCells(ps.Count  );
                    //if (ps.Count > 0)
                    //{
                    //   array.SetNumberOfTuples(nPts);
                    //}
                    //if (ps.Count <= 0)
                    //{
                    //   array.SetNumberOfTuples(0);
                    //}

                    pts.SetData(array);


                    #endregion



                    vtkQuad quad = vtkQuad.New();

                    grid.SetPoints(pts);
                    grid.SetCells(quad.GetCellType(), cellArray);



                    grid.GetCellData().SetScalars(scalarValue);


                    grid.Modified();

                }

                #endregion


            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("BuildGridLayer构造网格过程出错！" + e.Message);

                return;
            }


        }


        #endregion





        #endregion


        #region 公用方法 外接口

        /// <summary>
        /// Z轴缩放
        /// </summary>
        /// <param name="newScaleVector"></param>
        public void UpdateTransformScale(Vector newScaleVector)
        {
            //if (newScaleVector == null)
            //{
            //    return;
            //}

            //if (this.scaleVector == null)
            //{
            //    this.scaleVector = new Vector(1, 1, 1);
            //}


            this.scaleVector.X = newScaleVector.X;
            this.scaleVector.Y = newScaleVector.Y;
            this.scaleVector.Z = newScaleVector.Z;


            if (this.Transform  != null)
            {
                for (int i = 0; i < this.Transform .Count ; i++)
                {
                    if (this.Transform [i]!=null )
                    {
                        this.Transform[i].Identity();
                        this.Transform[i].Scale(this.scaleVector.X, this.scaleVector.Y, this.scaleVector.Z);
                    }

                }

            }




        }


        /// <summary>

        /// 更新 IBound 和 CellScalar 防止在外围赋值时两者都要调用对应的更新操作降低效率
        /// </summary>
        /// <param name="gridCellScalar"></param>
        /// <param name="iBound"></param>
        public void UpdateIBoundAndSclarData(List<double[,]> gridCellScalar, List<int[,]> iBound)
        {
            if (gridCellScalar ==null || iBound ==null ||this._contourData ==null )
            {
                return;
            }


            this._contourData = gridCellScalar;//不会触发更新操作
            //this.ContourData = gridCellScalar;//会触发更新操作


            this.EffectiveSign1 = iBound;//触发更新操作

        
        }



        /// <summary>
        ///等值线值  更新到vtkColorTransferFunction和vtkContourFilter 以及 图例标注的labelFormat（原因是：可能小数点变化了，导致格式变化）
        /// </summary>
        public void UpdateLookupTableAndContoourFilter()
        {

            if (this._layerLookupTable == null || this.contourFilter == null)
            {
                return;
            }

            

            for (int i = 0; i < this._layerLookupTable.Count; i++)
            {
                //vtkColorTransferFunction lt = this._layerLookupTable[i];
                vtkDiscretizableColorTransferFunction lt = this._layerLookupTable[i];

                lt.RemoveAllPoints();

                foreach (var item in this.ContourSetup.DisplayContours)
                {
                    lt.AddRGBPoint(item.Key, item.Value.R / 255.0, item.Value.G / 255.0, item.Value.B / 255.0);

                }

                lt.SetNumberOfValues(this.ContourSetup.DisplayContours.Count);

          

                lt.Build();

            }


            for (int i = 0; i < this.contourFilter.Count; i++)
            {
                vtkContourFilter contour = this.contourFilter[i];

                contour.SetNumberOfContours(this.ContourSetup.NumContours);

                int num = 0;
                foreach (double item in this.ContourSetup.DisplayContours.Keys)
                {
                    contour.SetValue(num, item);
                    num = num + 1;
                }
            }

            //当只是用vtkScalarBarActor的时候

            if (scalarBarActor != null && this._layerLookupTable.Count > 0)
            {
                scalarBarActor.SetLookupTable(this._layerLookupTable[0]);
                scalarBarActor.SetNumberOfLabels(this._layerLookupTable[0].GetNumberOfValues());

                scalarBarActor.SetLayerNumber(this._layerLookupTable[0].GetNumberOfValues());


                scalarBarActor.Modified();
            }

            //当使用vtkScalarBarWidget的时候

            if (scalarBarWidget !=null && this._layerLookupTable .Count >0)
            {
                  this.scalarBarWidget.GetScalarBarActor().SetLookupTable(this._layerLookupTable[0]);
                this.scalarBarWidget.GetScalarBarActor().SetNumberOfLabels(this._layerLookupTable[0].GetNumberOfValues());

                this.scalarBarWidget.GetScalarBarActor().SetLayerNumber(this._layerLookupTable[0].GetNumberOfValues());


                this.scalarBarWidget.GetScalarBarActor().Modified();

                this.scalarBarWidget.Modified();
            }


            //使用vtkScalarBarWidget的模式

            if (this.scalarBarWidget != null  )
            {

                if (this._contourSetup.ContourLineProperty.IsUseScientificNotation)
                {

                    //label样式
                    string labelFormat = "%-#2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "E";
                    //string labelFormat = "%2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                    //this.scalarBarActor.SetLabelFormat(labelFormat);
                    this.scalarBarWidget.GetScalarBarActor().SetLabelFormat(labelFormat);
                    //label样式
                    labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "E";
                    //labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "g";
                    if (ldmList != null)
                    {
                        for (int i = 0; i < ldmList.Count; i++)
                        {
                            ldmList[i].SetLabelFormat(labelFormat);
                        }
                    }
                }
                else
                {

                    //label样式
                    string labelFormat = "%-#2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                    //string labelFormat = "%2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                    //this.scalarBarActor.SetLabelFormat(labelFormat);
                    this.scalarBarWidget.GetScalarBarActor().SetLabelFormat(labelFormat);
                    //label样式
                    labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                    //labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "g";
                    if (ldmList != null)
                    {
                        for (int i = 0; i < ldmList.Count; i++)
                        {
                            ldmList[i].SetLabelFormat(labelFormat);
                        }
                    }

                }

                //只是用vtkScalarBarActor的模式

                //if (this._contourSetup.ContourLineProperty.IsSpecifyPrecision)
                //{
                //    //label样式
                //    string labelFormat = "%-#2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                //    //string labelFormat = "%2." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                //    this.scalarBarActor.SetLabelFormat(labelFormat);
                //    //label样式
                //    labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "f";
                //    //labelFormat = "%1." + this._contourSetup.ContourLineProperty.DecimalDigitNum.ToString() + "g";
                //    if (ldmList!=null )
                //    {
                //        for (int i = 0; i < ldmList.Count ; i++)
                //        {
                //             ldmList[i].SetLabelFormat(labelFormat);
                //        }
                //    }     

                //}
                //else
                //{

                //    //label样式
                //    string labelFormat = "%-#2.15f";
                //    this.scalarBarActor.SetLabelFormat(labelFormat);
                //    //label样式
                //    labelFormat = "%1.15f";
                //    //labelFormat = "%1.15g";
                //    if (ldmList != null)
                //    {
                //        for (int i = 0; i < ldmList.Count; i++)
                //        {
                //            ldmList[i].SetLabelFormat(labelFormat);
                //        }
                //    }  

                //}
            }














        }




       /// <summary>
       /// 等值线可见性
       /// </summary>
       /// <param name="isVisible"></param>
        public void UpdateContourLineVisibility(bool isVisible)
        {

            this._contourSetup.UpdateVisibility(isVisible);//首先更新配置信息

            //触发Actor可见性的判断更新
            if (this.ContourSetup.IsContours)
            {
                this.Visiability = true;
            }
            else
            {
                this.Visiability = false;
            }


        }

        /// <summary>
        /// 等值线模式  Layer  Grid
        /// </summary>
        /// <param name="contourMode"></param>
        public void UpdateContourLineCONTOURMODE(CONTOURMODE contourMode)
        {
            this._contourSetup.UpdateContourModel(contourMode);//首先更新配置信息

            //因为目前只是用  Layer  所以此处改变暂时不考虑
            if (this.ContourSetup.ContourMode == CONTOURMODE.LayerContours)
            {
            }
            else
            {

            }

        }
        /// <summary>
        /// 等值线值
        /// </summary>
        /// <param name="contourLines"></param>
        public void UpdateContourLineValueList(Dictionary<double, Color> contourLines)
        {

            this.ContourSetup.UpdateContourLineValue(contourLines );//首先更新配置信息


            this.UpdateLookupTableAndContoourFilter();//根据配置信息更新流水线


        }

        /// <summary>
        /// 等值线属性
        /// </summary>
        /// <param name="contourLineProperty"></param>
        public void UpdateContourLineProperty(ContourLineProperty contourLineProperty)
        {

            this._contourSetup.UpdateContourLineProperty(contourLineProperty);//首先更新配置信息



            for (int i = 0; i < this._layerActors.Count; i++)
            {
                if (this.ContourSetup.ContourLineProperty.ContourFillOrLine != CONTOURTYPE.Linear && this.ContourSetup.IsContours && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                {
                    this._visiability = true;
                    _layerActors[i].VisibilityOn();
                }
                else
                {
                    this._visiability = false;
                    _layerActors[i].VisibilityOff();
                }

            }

            for (int i = 0; i < this._contourLineMapper.Count; i++)
            {
                if (this.ContourSetup.ContourLineProperty.ContourFillOrLine != CONTOURTYPE.Linear)
                {

                    _contourLineMapper[i].ScalarVisibilityOff();
                    _contourLineActor[i].GetProperty().SetColor(0, 0, 0);//黑色
                }
                else
                {
                    _contourLineMapper[i].ScalarVisibilityOn();
                }

            }
            for (int i = 0; i < this._contourLineActor.Count; i++)
            {
                if (this.ContourSetup.ContourLineProperty.ContourFillOrLine != CONTOURTYPE.ColorFill && this.ContourSetup.IsContours && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                {
                    this._visiability = true;
                    _contourLineActor[i].VisibilityOn();
                    if (this.maskList != null && this.contourLabelsList != null && maskList.Count == contourLabelsList.Count)
                    {
                        if (this._contourSetup.Tagging.IsShowTagging)
                        {
                            //标注                  
                            this.contourLabelsList[i].VisibilityOn();
                        }
                        else
                        {
                            this.contourLabelsList[i].VisibilityOff();
                        }
                    }
                }
                else
                {
                    this._visiability = false;
                    _contourLineActor[i].VisibilityOff();

                    contourLabelsList[i].VisibilityOff();
                }


                _contourLineActor[i].GetProperty().SetLineWidth(this._contourSetup.ContourLineProperty.LineWidth);

                if (this._contourSetup.ContourLineProperty.ContourFillOrLine == CONTOURTYPE.LinearAndColorFill)
                {
                    _contourLineActor[i].GetProperty().SetColor(this._contourSetup.ContourLineProperty.LineColor.R / 255.0, this._contourSetup.ContourLineProperty.LineColor.G / 255.0, this._contourSetup.ContourLineProperty.LineColor.B / 255.0);
                }

            }

            //是否使用单元格的真实数据

            //for (int i = 0; i < this._layerMappers.Count; i++)
            //{
            //    if (this._contourSetup.ContourLineProperty.IsUseCellRealData)
            //    {
            //        _layerMappers[i].SetScalarModeToUseCellData();
            //    }
            //    else
            //    {
            //        _layerMappers[i].SetScalarModeToUsePointData();
            //    }
            //    _layerMappers[i].Modified();
            //    _layerMappers[i].Update();
            //}

            //for (int i = 0; i < this._contourLineMapper.Count; i++)
            //{
            //    if (this._contourSetup.ContourLineProperty.IsUseCellRealData)
            //    {
            //        _contourLineMapper[i].SetScalarModeToUseCellData();
            //    }
            //    else
            //    {
            //        _contourLineMapper[i].SetScalarModeToUsePointData();
            //    }
            //    _contourLineMapper[i].Modified();
            //    _contourLineMapper[i].Update();
            //}






            this.UpdateLookupTableAndContoourFilter();//二维结构需要，某一条等值线value不变，单独改变颜色color走的是属性事件，所以此处需要更新LookupTable


        }

      

        /// <summary>
        /// 图例
        /// </summary>
        /// <param name="scalarBar"></param>
        public void UpdateScalarBar(ContourScalarBar scalarBar)
        {
            this._contourSetup.UpdateScalarBar(scalarBar);//首先更新配置信息

            //if (this.scalarBarActor != null )
            //if ( this.scalarBarWidget != null)
            if (this.scalarBarActor != null && this.scalarBarWidget != null)
            {
                                                                             

                //颜色
                //this.scalarBarActor.GetLabelTextProperty().SetColor(this._contourSetup.ScalarBar.LabelColor.R / 255.0, this._contourSetup.ScalarBar.LabelColor.G / 255.0, this._contourSetup.ScalarBar.LabelColor.B / 255.0);
                this.scalarBarWidget .GetScalarBarActor ().GetLabelTextProperty().SetColor(this._contourSetup.ScalarBar.LabelColor.R / 255.0, this._contourSetup.ScalarBar.LabelColor.G / 255.0, this._contourSetup.ScalarBar.LabelColor.B / 255.0);
              

                //字号
                //this.scalarBarActor.GetLabelTextProperty().SetFontSize(this._contourSetup.ScalarBar.LabelFontSize);
                this.scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetFontSize(this._contourSetup.ScalarBar.LabelFontSize);
              

                //if (this._contourSetup.ScalarBar.IsDragable == false)
                //{
                //    #region      actor和widget  共存  问题：由actor转widget时，widget的位置无法控制

                //    scalarBarWidget.SetEnabled(0);
                //    //scalarBarWidget.SetEnabled(1);
                //    scalarBarWidget.SelectableOff();

                //    scalarBarWidget.Off();



                //    scalarBarWidget.GetScalarBarActor().SetWidth(this._contourSetup.ScalarBar.Width);
                //    scalarBarWidget.GetScalarBarActor().SetHeight(this._contourSetup.ScalarBar.Height);

                //    this.scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);


                //    scalarBarWidget.RepositionableOff();//移动                 
                //    scalarBarWidget.ResizableOff();//大小

                //    #endregion


                //    #region

                //    //scalarBarWidget.SetEnabled(1);
                //    ////scalarBarWidget.SetEnabled(1);
                //    //scalarBarWidget.SelectableOff();
                //    ////scalarBarWidget.SelectableOn ();


                //    //scalarBarWidget.Off();
                //    ////scalarBarWidget.On();


                //    //scalarBarWidget.GetScalarBarActor().SetWidth(this._contourSetup.ScalarBar.Width);
                //    //scalarBarWidget.GetScalarBarActor().SetHeight(this._contourSetup.ScalarBar.Height);

                //    //this.scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);


                //    //scalarBarWidget.RepositionableOff();//移动                 
                //    //scalarBarWidget.ResizableOff();//大小   
                //    //scalarBarWidget.RepositionableOn();//移动                 
                //    //scalarBarWidget.ResizableOn();//大小 


                //    //scalarBarWidget.GetScalarBarActor().Modified();
                //    //scalarBarWidget.Render();


                //    ////scalarBarWidget.RepositionableOff();//移动                 
                //    ////scalarBarWidget.ResizableOff();//大小  

                //    #endregion

                //}
                //else
                //{
                    #region    actor和widget  共存  问题：由actor转widget时，widget的位置无法控制

                    scalarBarWidget.SetEnabled(1);
                    //scalarBarWidget.SelectableOn();
                    scalarBarWidget.SelectableOff();

                    scalarBarWidget.On();


                    scalarBarWidget.GetScalarBarActor().SetWidth(this._contourSetup.ScalarBar.Width);
                    scalarBarWidget.GetScalarBarActor().SetHeight(this._contourSetup.ScalarBar.Height);

                    this.scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);





                    scalarBarWidget.RepositionableOn();//移动                 
                    scalarBarWidget.ResizableOn();//大小    

                    #endregion


                    #region

                    //scalarBarWidget.SetEnabled(1);      
                    //scalarBarWidget.SelectableOff();
                    ////scalarBarWidget.SelectableOn ();
                    //scalarBarWidget.Off ();
                    ////scalarBarWidget.On();

                    
                    //scalarBarWidget.GetScalarBarActor().SetWidth(this._contourSetup.ScalarBar.Width);
                    //scalarBarWidget.GetScalarBarActor().SetHeight(this._contourSetup.ScalarBar.Height);

                    //this.scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);

                    //scalarBarWidget.RepositionableOff();//移动                 
                    //scalarBarWidget.ResizableOff();//大小   
                    ////scalarBarWidget.RepositionableOn();//移动                 
                    ////scalarBarWidget.ResizableOn();//大小 


                    //scalarBarWidget.GetScalarBarActor().Modified();
                    ////scalarBarWidget.Modified();
                    //scalarBarWidget.Render();




                    ////scalarBarWidget.SetEnabled(1);
                    ////scalarBarWidget.SelectableOff();        
                    //scalarBarWidget.On();


                    ////scalarBarWidget.RepositionableOn();//移动                 
                    ////scalarBarWidget.ResizableOn();//大小    

                    #endregion

                    #region

                    //scalarBarWidget.SetEnabled(1);
                    ////scalarBarWidget.SelectableOn();
                    //scalarBarWidget.SelectableOff();

                    //scalarBarWidget.On();


                    //scalarBarWidget.GetScalarBarActor().SetWidth(this._contourSetup.ScalarBar.Width);
                    //scalarBarWidget.GetScalarBarActor().SetHeight(this._contourSetup.ScalarBar.Height);

                    //this.scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);





                    //scalarBarWidget.RepositionableOn();//移动                 
                    //scalarBarWidget.ResizableOn();//大小    

                    //scalarBarWidget.Render();

                    #endregion


                //}




                //scalarBarWidget.SetEnabled(1);
                //scalarBarWidget.SelectableOff();

                //this.scalarBarWidget.On();//Methods for turning the interactor observer on and off

                //     Indicate whether the interior region of the widget can be selected or not.
                //     If not, then events (such as left mouse down) allow the user to "move" the
                //     widget, and no selection is possible. Otherwise the SelectRegion() method
                //     is invoked.
                //scalarBarWidget.SelectableOn();//不能选择，则不能够移动，但是不影响大小

                //     ProcessEvents (On by default)
                //     must be On for Enabled widget to respond to interaction. If ProcessEvents
                //     is Off, enabling/disabling a widget merely affects the visibility of the
                //     representation.
                //scalarBarWidget.SetEnabled(1);

                //     Can the widget be moved. On by default. If off, the widget cannot be moved
                //     around. 
            //    scalarBarWidget.RepositionableOn();//移动

                //     Indicate whether the boundary of the widget can be resized.  If not, the
                //     cursor will not change to "resize" type when mouse over the boundary.
            //    scalarBarWidget.ResizableOn();//大小


                ////宽度
                //this.scalarBarActor.SetWidth(this._contourSetup.ScalarBar.Width);
                ////高度
                //this.scalarBarActor.SetHeight(this._contourSetup.ScalarBar.Height);
                ////左下角坐标
               
                //this.scalarBarActor.GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);
                //this.scalarBarActor.GetPositionCoordinate().SetValue(100, 200);//像素 pixels
                //this.scalarBarActor.GetPositionCoordinate().SetValue(0.1, 0.2);//比例

             

                //this.scalarBarActor.GetLabelTextProperty().SetOpacity(1);
                this.scalarBarWidget.GetScalarBarActor().GetLabelTextProperty().SetOpacity(1);



                //可见性
                if (this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                {
                    //if (this.ContourSetup.IsContours)

                    if (this._contourSetup.ScalarBar.IsShowScalarBar)
                    {
                        this.scalarBarActor.VisibilityOn();

                        //this.scalarBarWidget.On();//Methods for turning the interactor observer on and off
                        //scalarBarWidget.SetEnabled(1);

                    }
                    else
                    {
                        this.scalarBarActor.VisibilityOff();

                        //this.scalarBarWidget.Off();//Methods for turning the interactor observer on and off
                        scalarBarWidget.SetEnabled(0);

                    }
                }
                else
                {
                    this.scalarBarActor.VisibilityOff();

                    //this.scalarBarWidget.Off();//Methods for turning the interactor observer on and off
                    scalarBarWidget.SetEnabled(0);

                }






                #region
                //vtkTextProperty property = vtkTextProperty.New();
                //property.SetColor(this._contourSetup.ScalarBar.TitleColor.R / 255.0, this._contourSetup.ScalarBar.TitleColor.G / 255.0, this._contourSetup.ScalarBar.TitleColor.B / 255.0);
                //property.SetFontSize(this._contourSetup.ScalarBar.LabelFontSize);                      
                //property.SetVerticalJustificationToCentered();//label中的数字靠近颜色区域的底部？？
                //property.SetFontFamilyToTimes();
                //property.SetOpacity(0.5);
                //this.scalarBarActor.SetLabelTextProperty(property );
                //this.scalarBarActor.SetNumberOfLabels(3);
                //this.scalarBarActor.SetLayerNumber(4);
                //this.scalarBarActor.VisibilityOn();
                //this.scalarBarActor.Modified();
              


                ////移动
                //if (this._contourSetup.ScalarBar.IsDragable)
                //{
                //    //this.scalarBarActor.DragableOn();
                //    this.scalarBarWidget.ResizableOn();
                //    this.scalarBarWidget.RepositionableOn();

                //}
                //else
                //{
                //    //this.scalarBarActor.DragableOff();

                //    this.scalarBarWidget.ResizableOff ();
                //    this.scalarBarWidget.RepositionableOff ();

                //}
                #endregion




                this.scalarBarActor.GetLabelTextProperty().Modified();

                if (this.scalarBarActor != null)
                {
                    this.scalarBarActor.Modified();
                }

                if (this.scalarBarWidget !=null )
                {
                     scalarBarWidget.Modified();
                }
               

            }

        }

        /// <summary>
        /// 标注
        /// </summary>
        /// <param name="tagging"></param>
        public void UpdateTagging(ContourTagging tagging)
        {
            //if (this.ParentNode == null)
            //{
            //    return;

            //}

            //if (!this.ParentNode.Scene.IsRendering)
            //{
            //    return;

            //}

            this._contourSetup.UpdateTagging(tagging);//首先更新配置信息


            if (this.maskList  != null&& this.contourLabelsList !=null && maskList .Count ==contourLabelsList .Count )
            {
                for (int i = 0; i < this.maskList.Count; i++)
                {

                    if (this.maskList[i] != null&& contourLabelsList [i]!=null&& ldmList [i]!=null  )
                    {
                        //可见性
                        if (this._visiability && this.ContourSetup.DisplayContours.Count > 0 && this._contourData.Count > 0)
                        {
                            //if (this.ContourSetup.IsContours)

                            if (this._contourSetup.Tagging .IsShowTagging )
                            {
                                //this.scalarBarActor.VisibilityOn();
                                this.contourLabelsList[i].VisibilityOn();
                            }
                            else
                            {
                                //this.scalarBarActor.VisibilityOff();
                                this.contourLabelsList[i].VisibilityOff();
                            }
                        }
                        else
                        {
                            //this.scalarBarActor.VisibilityOff();
                            this.contourLabelsList[i].VisibilityOff();

                        }


                        //采样点
                        if (this.ContourSetup.Tagging.MaskPointNum <= 0)
                        {
                            this.maskList[i].SetMaximumNumberOfPoints(1);
                        }
                        else 
                        {
                            this.maskList[i].SetMaximumNumberOfPoints(this.ContourSetup.Tagging.MaskPointNum);
                        }
                        //this.maskList[i].SetMaximumNumberOfPoints(this.ContourSetup.Tagging.MaskPointNum);

                        //颜色
                        ldmList[i].GetLabelTextProperty().SetColor(this._contourSetup.Tagging.TagColor.R / 255.0, this._contourSetup.Tagging.TagColor.G / 255.0, this._contourSetup.Tagging.TagColor.B / 255.0);

                        //字号
                        if (this._contourSetup.Tagging.FontSize <= 0)
                        {
                            ldmList[i].GetLabelTextProperty().SetFontSize(1);
                        }
                        else 
                        {
                            ldmList[i].GetLabelTextProperty().SetFontSize(this._contourSetup.Tagging.FontSize);
                        }

                        //ldmList[i].GetLabelTextProperty().SetFontSize(this._contourSetup.Tagging.FontSize);
  

                    }

                }
            }


        }



        #endregion




        #region Filter属性重写  可见性 ，显示类型等


        /// <summary>
        /// 重写可见性属性
        /// </summary>

        protected override void OnSetVisibility()
        {
            base.OnSetVisibility();

            if (this.ParentNode.Scene == null)
            {
                return;

            }
            if (this.ContourSetup ==null )
            {
                //等值线
                for (int i = 0; i < this._layerActors .Count ; i++)
                {
                    this._layerActors[i].VisibilityOff();
                }

                for (int i = 0; i < this._contourLineActor .Count ; i++)
                {
                    this._contourLineActor[i].VisibilityOff();
                }

                //图例
                if (this.scalarBarActor!=null )
                {
                    this.scalarBarActor.VisibilityOff();
         
                }
                if (this.scalarBarWidget !=null )
                {
                    this.scalarBarWidget.SetEnabled(0);
                    this.scalarBarWidget.Off();
                }

                if (this.isoActor !=null )
                {
                    this.isoActor.VisibilityOff();
                }

                //标注
                if (this.contourLabels !=null )
                {
                    this.contourLabels.VisibilityOff();
                }
                if (this.contourLabelsList !=null )
                {
                    for (int i = 0; i < this.contourLabelsList.Count; i++)
                    {
                        this.contourLabelsList[i].VisibilityOff();

                    }
                }

                return;

            }
            //if (this.ParentNode.Scene.IsRendering)
            {
                if (this._visiability==true && this.ContourSetup .DisplayContours .Count >0 && this._contourData .Count >0)
                {
                    //等值线
                    if (this.ContourSetup.ContourLineProperty .ContourFillOrLine  != CONTOURTYPE.Linear)
                    {
                        for (int i = 0; i < this._layerActors.Count; i++)
                        {
                            this._layerActors[i].VisibilityOn();
                        }
                    }
                    else
                    {
                        for (int i = 0; i < this._layerActors.Count; i++)
                        {
                            this._layerActors[i].VisibilityOff ();
                        }
                    }


                    if (this.ContourSetup.ContourLineProperty .ContourFillOrLine  != CONTOURTYPE.ColorFill)
                    {
                        for (int i = 0; i < this._contourLineActor.Count; i++)
                        {
                            this._contourLineActor[i].VisibilityOn();
                        }
                    }
                    else
                    {
                        for (int i = 0; i < this._contourLineActor.Count; i++)
                        {
                            this._contourLineActor[i].VisibilityOff ();
                        }
                    }

                    //图例
                    if (this.scalarBarActor != null)
                    {
                        if (this._contourSetup .IsContours ==true && this._contourSetup.ScalarBar.IsShowScalarBar)
                        {
                            this.scalarBarActor.VisibilityOn();

                            if (this.scalarBarWidget != null)
                            {

                                //if (this._contourSetup.ScalarBar.IsDragable == false)
                                //{

                                //    scalarBarWidget.SetEnabled(0);
                                //    //scalarBarWidget.SetEnabled(1);
                                //    scalarBarWidget.SelectableOff();

                                //    scalarBarWidget.Off();

                                //    scalarBarWidget.GetScalarBarActor().SetWidth(this._contourSetup.ScalarBar.Width);
                                //    scalarBarWidget.GetScalarBarActor().SetHeight(this._contourSetup.ScalarBar.Height);

                                //    this.scalarBarWidget.GetScalarBarActor().GetPositionCoordinate().SetValue(this._contourSetup.ScalarBar.XLowLeftToViewPort, this._contourSetup.ScalarBar.YLowLeftToViewPort);
                                    
                                //}
                                //else
                                //{
                                    scalarBarWidget.SetEnabled(1);
                                    //scalarBarWidget.SelectableOn();
                                    scalarBarWidget.SelectableOff();

                                    scalarBarWidget.On();

                                //}


                            }
                        }
                        else 
                        {

                            this.scalarBarActor.VisibilityOff ();

                            if (this.scalarBarWidget !=null )
                            {
                                this.scalarBarWidget.SetEnabled(0);

                                this.scalarBarWidget.Off();

                            }

                        }
                      
                    }

                    //if (this.scalarBarWidget  != null)
                    //{
                    //    if (this._contourSetup.IsContours == true && this._contourSetup.ScalarBar.IsShowScalarBar)
                    //    {
                    //        this.scalarBarWidget.On ();

                    //    }
                    //    else
                    //    {
                    //        this.scalarBarWidget.Off ();

                    //    }

                    //}


                    if (this.isoActor !=null )
                    {
                        if (this._contourSetup.IsContours == true && this._contourSetup.ScalarBar.IsShowScalarBar)
                        {
                            this.isoActor.VisibilityOn();

                        }
                        else
                        {
                            this.isoActor.VisibilityOff ();
                        
                        }

                      

                    }

                    //标注
                    if (this.contourLabels != null)
                    {
                        if (this._contourSetup.IsContours == true && this._contourSetup.Tagging.IsShowTagging)
                        {
                            this.contourLabels.VisibilityOn  ();
                        }
                        else       
                        {
                            this.contourLabels.VisibilityOff ();
                        }

                        
                    }
                    if (this.contourLabelsList != null)
                    {
                        if (this._contourSetup.IsContours && this._contourSetup.Tagging.IsShowTagging)
                        {
                            for (int i = 0; i < this.contourLabelsList.Count; i++)
                            {
                                this.contourLabelsList[i].VisibilityOn();

                            }

                        }
                        else 
                        {
                            for (int i = 0; i < this.contourLabelsList.Count; i++)
                            {
                                this.contourLabelsList[i].VisibilityOff ();

                            }
                        }
                       
                    }


                }
                else
                {
                    //等值线
                    for (int i = 0; i < this._layerActors.Count; i++)
                    {
                        this._layerActors[i].VisibilityOff();
                    }

                    for (int i = 0; i < this._contourLineActor.Count; i++)
                    {
                        this._contourLineActor[i].VisibilityOff();
                    }
                    //图例
                    if (this.scalarBarActor != null)
                    {
                        this.scalarBarActor.VisibilityOff();
                    }

                    if (this.scalarBarWidget !=null )
                    {
                        this.scalarBarWidget.SetEnabled(0);
                        this.scalarBarWidget.Off();
                    }
                    if (this.isoActor != null)
                    {
                        this.isoActor.VisibilityOff();
                    }

                    //标注
                    if (this.contourLabels != null)
                    {
                        this.contourLabels.VisibilityOff();
                    }
                    if (this.contourLabelsList != null)
                    {
                        for (int i = 0; i < this.contourLabelsList.Count; i++)
                        {
                            this.contourLabelsList[i].VisibilityOff();

                        }
                    }

                }


                this.ParentNode.Scene.Update();
            }


        }

        protected override void OnSetRepresentationType()
        {
            base.OnSetRepresentationType();


            if (this.ParentNode.Scene == null)
            {
                return;

            }

            if (this.ParentNode.Scene.IsRendering)
            {
                if (this._repType == REPRESENTATIONTYPE.POINT)
                {
                    this.isoActor.GetProperty().SetRepresentationToPoints();
                }
                else if (this._repType == REPRESENTATIONTYPE.SURFACE)
                {
                    this.isoActor.GetProperty().SetRepresentationToSurface();
                }
                else
                {
                    this.isoActor.GetProperty().SetRepresentationToWireframe();
                }
                //this.scene.Update();
            }

        }

        protected override void OnSetContourType()
        {
            base.OnSetContourType();

            if (this.ParentNode.Scene == null)
            {
                return;

            }

            if (this.ParentNode.Scene.IsRendering)
            {
                if (this._contourType == CONTOURTYPE.Linear)
                {
                    this.isoMapper.ScalarVisibilityOn();
                }
                else if (this._contourType == CONTOURTYPE.ColorFill)
                {
                    this.isoMapper.ScalarVisibilityOff();
                }
                else if (this._contourType == CONTOURTYPE.LinearAndColorFill)
                {
                    this.isoMapper.ScalarVisibilityOn();
                }


                this.ParentNode.Scene.Update();

            }

        }


        #endregion

       




 

    }



}
